Why doesn't this RE match?
MRAB
google at mrabarnett.plus.com
Fri Feb 6 19:34:52 EST 2009
Just Another Victim of the Ambient Morality wrote:
> I'm confused by this behaviour:
>
>
> import re
>
> regex = re.compile('foo')
> match = regex.match('whatfooever')
>
>
> In my experience with regular expressions, regex should have found a
> match. However, in this case regex.match() returns None. Why is that?
> What am I missing?
> Thank you...
>
match() is anchored at (ie matches only at) the start of the string. You
need search(). It's in the docs! :-)
More information about the Python-list
mailing list