How Can I Use Pcre Regexes From A Python Script?
Solution 1:
Tor, unearthing this old question because it's a good one, and still timely for anyone who wants to move a project from PHP to python.
I too am a big fan of PCRE. On Python, re
is quite limited, but the good news is that there's another module called regex
that offers many of the wonderful features of PCRE, including:
- Atomic Groups
- Possessive Quantifiers
- Recursion
- Branch Reset
and many more, including several that PCRE doesn't offer, such as class subtraction, variable-length lookbehind and fuzzy matching.
If the developers carry the project to fruition, Python will suddenly be equipped with an outstanding regex engine, which will make it more attractive to regex lovers who have been on the fence about switching from PHP.
Read the directions carefully, because the module can be run in two modes, one for compatibility with re
, the other with all the cool features. You specify the mode with (?V0)
or (?V1)
On Unix, installation with pip is a snap. On Windows, I haven't managed to get the regex
module to work with a 64-bit python. I uninstalled my 64-bit installs of 2.7 and 3.3, reinstalled in 32-bit, and installed the regex
module on both.
Places to go from here:
Post a Comment for "How Can I Use Pcre Regexes From A Python Script?"