re. module

Adrian Leu AdrianLeu at kelseus.com
Wed Nov 14 10:31:43 EST 2001


I am trying to figure out a solution for the following:

import re

text = 'name_0 goto place'
string = 'name|name_0|name_1'

pattern = re.compile(string, re.I)
d = pattern.search(text)
return d.group(0)

The problem is that my program will return 'name' to this. What I want
is for the search to return a match (if it exists) only after looking
at the whole string (name_0 in this case). I.e. in my example I would
like the program to return 'name_0' not 'name'.

Any ideas how I could do that?

Thanks.

Adrian.



More information about the Python-list mailing list