tags:

views:

304

answers:

2

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

+6  A: 
r = re.compile('some[pattern]');
print r.pattern
chaos
+15  A: 

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)*'
dcrosta
Wow great, why can't I see it if I do a dir(regex) ?? I tried to introspect but cannot find where this property comes from...
nabucosound