Python Regular Expressions – Flavor and Usage

pythonregular expressions

So my copy of the classic book, Mastering Regular Expressions, just arrived, and I'm scanning through it. The cover (third edition) says, "for Perl, PHP, Java, .NET, Ruby, and More!" Well, it does have a full chapter for each of Perl, PHP, Java, and .NET – but no chapter on Ruby, or, more importantly to me, on Python.

Although the index lists a few points of Python's differences (such as how it handles newlines), there's not even a table of them, much less an entire chapter.

Which of the four covered languages, is Python's regex engine most similar to? More importantly, how similar, and what are the major differences?

Note – I don't mean how regexes are used in Python (versus, say Perl) – I know and use the re module. I'm only interested in the syntax differences of the actual regexes.

Best Answer

This site has a table comparing regex features for a wide range of languages and platforms (make sure to scroll to the bottom). There's also a page specific to Python, with more info about the re module (though, for a more complete regex library in Python, you should also look at the newer regex module).

Related Topic