Pattern matching with string and list
olaufr at gmail.com
olaufr at gmail.com
Mon Dec 12 18:05:53 EST 2005
Hi,
I'd need to perform simple pattern matching within a string using a
list of possible patterns. For example, I want to know if the substring
starting at position n matches any of the string I have a list, as
below:
sentence = "the color is $red"
patterns = ["blue","red","yellow"]
pos = sentence.find($)
# here I need to find whether what's after 'pos' matches any of the
strings of my 'patterns' list
bmatch = ismatching( sentence[pos:], patterns)
Is an equivalent of this ismatching() function existing in some Python
lib?
Thanks,
Olivier.
More information about the Python-list
mailing list