Pattern matching with string and list

BartlebyScrivener rpdooling at gmail.com
Tue Dec 13 08:28:08 EST 2005


Taking you literally, I'm not sure you need regex. If you know or can
find position n, then can't you just:

sentence = "the color is $red"
patterns = ["blue","red","yellow"]
pos = sentence.find("$")
for x in patterns:
    if x==sentence[pos+1:]:
        print x, pos+1

But maybe I'm oversimplifying.

rpd




More information about the Python-list mailing list