Mykola Kharechko Mykola Kharechko - 4 months ago 6
Python Question

how can i obtain pattern string from compiled regexp pattern in python

I have some code like this one:

>>> import re
>>> p = re.compile('my pattern')
>>> print p
_sre.SRE_Pattern object at 0x02274380


Is it possible to get string
"my pattern"
from
p
variable?

Answer
p.pattern

Read more about re module here: http://docs.python.org/library/re.html