re.compile

Andrew Dalke adalke at mindspring.com
Mon Nov 1 20:05:34 EST 2004


Brad Tilley wrote:
> Is there a quick way to make re.compile show what it's looking for?
> 
> x = re.compile('[a-z]')


What do you want?

 >>> import re
 >>> x = re.compile('[a-z]')
 >>> x.pattern
'[a-z]'
 >>> import sre_parse  # undocumented internal module ;)
 >>> sre_parse.parse(x.pattern)
[('in', [('range', (97, 122))])]
 >>>

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list