regex alternation problem

2009-04-17 Thread Jesse Aldridge
import re s1 = I am an american s2 = I am american an for s in [s1, s2]: print re.findall( (am|an) , s) # Results: # ['am'] # ['am', 'an'] --- I want the results to be the same for each string. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list

Re: regex alternation problem

2009-04-17 Thread Eugene Perederey
According to documentation re.findall takes a compiled pattern as a first argument. So try patt = re.compile(r'(am|an)') re.findall(patt, s1) re.findall(patt, s2) 2009/4/18 Jesse Aldridge jessealdri...@gmail.com: import re s1 = I am an american s2 = I am american an for s in [s1, s2]:    

Re: regex alternation problem

2009-04-17 Thread Robert Kern
On 2009-04-17 16:57, Eugene Perederey wrote: According to documentation re.findall takes a compiled pattern as a first argument. So try patt = re.compile(r'(am|an)') re.findall(patt, s1) re.findall(patt, s2) No, it will take a string pattern, too. -- Robert Kern I have come to believe that

Re: regex alternation problem

2009-04-17 Thread Robert Kern
On 2009-04-17 16:49, Jesse Aldridge wrote: import re s1 = I am an american s2 = I am american an for s in [s1, s2]: print re.findall( (am|an) , s) # Results: # ['am'] # ['am', 'an'] --- I want the results to be the same for each string. What am I doing wrong? findall() finds

Re: regex alternation problem

2009-04-17 Thread Tim Chase
s1 = I am an american s2 = I am american an for s in [s1, s2]: print re.findall( (am|an) , s) # Results: # ['am'] # ['am', 'an'] --- I want the results to be the same for each string. What am I doing wrong? In your first case, the regexp is consuming the am (four characters,

Re: regex alternation problem

2009-04-17 Thread Paul McGuire
On Apr 17, 4:49 pm, Jesse Aldridge jessealdri...@gmail.com wrote: import re s1 = I am an american s2 = I am american an for s in [s1, s2]:     print re.findall( (am|an) , s) # Results: # ['am'] # ['am', 'an'] --- I want the results to be the same for each string.  What am I

Re: regex alternation problem

2009-04-17 Thread Paul McGuire
On Apr 17, 5:28 pm, Paul McGuire pt...@austin.rr.com wrote: -- Paul Your find pattern includes (and consumes) a leading AND trailing space around each word.  In the first string I am an american, there is a leading and trailing space around am, but the trailing space for am is the leading

Re: regex alternation problem

2009-04-17 Thread Jesse Aldridge
On Apr 17, 5:30 pm, Paul McGuire pt...@austin.rr.com wrote: On Apr 17, 5:28 pm, Paul McGuire pt...@austin.rr.com wrote: -- Paul Your find pattern includes (and consumes) a leading AND trailing space around each word.  In the first string I am an american, there is a leading and trailing