Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decompile a regex?

Tags:

python

regex

Is there any way to decompile a regular expression once compiled?

like image 215
nabucosound Avatar asked Sep 22 '09 15:09

nabucosound


2 Answers

Compiled regular expression objects have a "pattern" attribute which gives the original text pattern.

>>> import re
>>> regex = re.compile('foo (?:bar)*')
>>> regex.pattern
'foo (?:bar)*'
like image 193
dcrosta Avatar answered Oct 08 '22 15:10

dcrosta


r = re.compile('some[pattern]');
print r.pattern
like image 28
chaos Avatar answered Oct 08 '22 15:10

chaos