On 2009-02-06 18:23, 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?

http://docs.python.org/library/re#re.RegexObject.match

Basically, regex.match() tries to apply the regexp to the beginning of the string. Use regex.search() to search for a match later in the string.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to