spaces in re.compile()

rbt rbt at athop1.ath.vt.edu
Mon Mar 21 13:53:27 EST 2005


Jeff Epler wrote:
> 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")

That works great. Thanks for the tip!



More information about the Python-list mailing list