Puzzled about this regex
clp2 at rebertia.com
Sat Apr 18 04:21:31 CEST 2009
On Fri, Apr 17, 2009 at 7:17 PM, Jean-Claude Neveu
<jcn-france1972 at pobox.com> wrote:
> I wonder if someone could tell me where I am going wrong with my regular
> expression, please. My regex only matches the text I'm looking for (a number
> followed by a distance unit) when it appears at the beginning of the string.
> But I am not using the ^ character (which would indicate that I only want a
> match if it is at the start).
Reading the fine manual, http://docs.python.org/library/re.html :
re.match(pattern, string[, flags])
If zero or more characters at the beginning of string match the
regular expression pattern, return a corresponding MatchObject
instance. Return None if the string does not match the pattern; note
that this is different from a zero-length match.
***Note: If you want to locate a match anywhere in string, use
re.search(pattern, string[, flags])
Scan through string looking for a location where the regular
expression pattern produces a match, and return a corresponding
MatchObject instance. Return None if no position in the string matches
the pattern; note that this is different from finding a zero-length
match at some point in the string.
I have a blog:
More information about the Python-list