regex alternation problem

Eugene Perederey eugene.perederey at gmail.com
Fri Apr 17 23:57:04 CEST 2009


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 <JesseAldridge at gmail.com>:
> 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
>



-- 
Sincerely yours, Eugene Perederey



More information about the Python-list mailing list