Re: Pattern matching with string and list

2005-12-13 Thread Brett g Porter
BartlebyScrivener wrote: > Even without the marker, can't you do: > > sentence = "the fabric is red" > colors = ["red", "white", "blue"] > > for color in colors: > if (sentence.find(color) > 0): > print color, sentence.find(color) > That depends on whether you're only looking for who

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
Even without the marker, can't you do: sentence = "the fabric is red" colors = ["red", "white", "blue"] for color in colors: if (sentence.find(color) > 0): print color, sentence.find(color) -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern matching with string and list

2005-12-13 Thread BartlebyScrivener
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 oversimplifyin

Re: Pattern matching with string and list

2005-12-12 Thread Tom Anderson
On Mon, 12 Dec 2005 [EMAIL PROTECTED] wrote: > 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

Re: Pattern matching with string and list

2005-12-12 Thread Michael Spencer
[EMAIL PROTECTED] wrote: > 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" > patte