How to escape # hash character in regex match strings

504crank at 504crank at
Wed Jun 10 10:47:13 EDT 2009

I've encountered a problem with my RegEx learning curve -- how to
escape hash characters # in strings being matched, e.g.:

>>> string = re.escape('123#abc456')
>>> match = re.match('\d+', string)
>>> print match

<_sre.SRE_Match object at 0x00A6A800>
>>> print


The correct result should be:


I've tried to escape the hash symbol in the match string without

Any ideas? Is the answer something I overlooked in my lurching Python

More information about the Python-list mailing list