Captain Macheath is a fictional character who appears both in John Gay's The Beggar's Opera (1728), its sequel Polly (1777), and roughly 150 years later in Bertolt Brecht's The Threepenny Opera (1928).
He was probably inspired in part by Jack Sheppard who, like Macheath, escaped from prison and enjoyed the affections of a prostitute, and despised violence. His nemesis is Peachum who, in John Gay's original work, keeps an account book of unproductive thieves (something that Macheath himself does in Bertolt Brecht's work). Both characters can be understood as satires of Robert Walpole and Jonathan Wild.
In popular culture
He is quoted by Bar, a lawyer attending a dinner party held by Mr Merdle: “a high and solemn occasion, when, as Captain Macheath says, "the judges are met: a terrible show!" We lawyers are sufficiently liberal, you see, to quote the Captain, though the Captain is severe upon us. Nevertheless, I think I could put in evidence an admission of the Captain's,' said Bar, with a little jocose roll of his head; for, in his legal current of speech, he always assumed the air of rallying himself with the best grace in the world; 'an admission of the Captain's that Law, in the gross, is at least intended to be impartial. For what says the Captain, if I quote him correctly—and if not,' with a light-comedy touch of his double eye-glass on his companion's shoulder, 'my learned friend will set me right:
"Since laws were made for every degree, To curb vice in others as well as in me, I wonder we ha'n't better company Upon Tyburn Tree!"” 
In The Threepenny Opera
In Bertolt Brecht's The Threepenny Opera, he is referred to as "Mack the Knife", and is the subject of the song of the same name. Whilst his character plays roughly the same role as in the work it is derived from, Macheath is a much less romantic character here, described as a cutthroat, rapist and seducer of underage girls.
- Straight Dope Staff Report: What's the story behind "Mack the Knife"?
- Moore, Lucy (1997). The Thieves' Opera. Viking. p. 227. ISBN 0-670-87215-6.
- Excerpt From: Charles Dickens. “Little Dorrit”. Apple Books. https://books.apple.com/ie/book/little-dorrit/id498919141