spaces in re.compile()

Jeff Epler jepler at
Mon Mar 21 17:44:50 CET 2005

Maybe you want r'\b'.  From 'pydoc sre':
    \b       Matches the empty string, but only at the start or end of a word.

import re
r = re.compile( r'\btest\b' )
print r.findall("testy")
print r.findall(" testy ")
print r.findall(" test ")
print r.findall("test")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list