Python regular expression question!

unexpected sumesh.chopra at gmail.com
Wed Sep 20 12:54:21 EDT 2006


I'm trying to do a whole word pattern match for the term 'MULTX-'

Currently, my regular expression syntax is:

re.search(('^')+(keyword+'\\b')

where keyword comes from a list of terms. ('MULTX-' is in this list,
and hence a keyword).

My regular expression works for a variety of different keywords except
for 'MULTX-'. It does work for MULTX, however, so I'm thinking that the
'-' sign is delimited as a word boundary. Is there any way to get
Python to override this word boundary?

I've tried using raw strings, but the syntax is painful. My attempts
were:

re.search(('^')+("r"+keyword+'\b')
re.search(('^')+("r'"+keyword+'\b')

and then tried the even simpler:

re.search(('^')+("r'"+keyword)
re.search(('^')+("r''"+keyword)


and all of those failed for everything. Any suggestions?




More information about the Python-list mailing list