Monday, February 21, 2011

Getting the pattern back from a compiled re?

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?

From stackoverflow
  • You can get it back with

    x.pattern
    

    from the Python Regular Expression Objects page

    Bartosz Radaczyński : bill, do you know why dir(x) does not show pattern in the list?
    Bill the Lizard : I'm not sure. It could be because it's not a method, but a property.
    Bartosz Radaczyński : I'll post another question :)
    Bill the Lizard : Good idea, now I'm interested to know. :)
    Bartosz Radaczyński : 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

0 comments:

Post a Comment