tags:

views:

101

answers:

1

Hi all. Assume I have created a compiled re:

x = re.compile('^\d+$')

Is there a way to extract the pattern string (^\d+$) back from the x?

+8  A: 

You can get it back with

x.pattern

from the Python Regular Expression Objects page

Bill the Lizard
bill, do you know why dir(x) does not show pattern in the list?
Bartosz Radaczyński
I'm not sure. It could be because it's not a method, but a property.
Bill the Lizard
I'll post another question :)
Bartosz Radaczyński
Good idea, now I'm interested to know. :)
Bill the Lizard
I actually rephrased it a bit, since the docs say that the list need not to be complete (whatever Guido means by this statement...). check it out here: http://stackoverflow.com/questions/191010/how-to-get-a-complete-list-of-objects-methods-and-attributes
Bartosz Radaczyński