Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Regular Expression flavour is used in Python?

I want to know which RegEx-flavour is used for Python? Is it PCRE, Perl compatible or is it ICU or something else?

like image 424
extreme001 Avatar asked Aug 18 '12 21:08

extreme001


2 Answers

It's compatible enough w/ Perl, meaning most Perl expressions will work unmodified. It aims to be Perl compatible but, of course, there are some minor differences.

It, technically, uses its own flavor of regular expressions. For instance, named groups were offered in Python regex long-before other implementations adopted the syntax. It also supports Unicode out of the box. Most Python extensions are supported elsewhere these days. See http://docs.python.org/library/re.html

like image 87
pestilence669 Avatar answered Oct 12 '22 03:10

pestilence669


Unfortunately I cannot answer directly to the comment, but atomic blocks are an important feature (although few people understand their power), since you can create multibyte character sequences with it. I.e. in Windows a newline is \r\n.

Example: /(?>\r\n|\n|\r)\p{Any}/ matches to \n\r or \r., because that is a combination of a newline and any character literal, but it does not match to \r\n since nothing follows the newline.

like image 29
dark100 Avatar answered Oct 12 '22 03:10

dark100