Puzzled about this regex
Chris Rebert
clp2 at rebertia.com
Fri Apr 17 22:21:31 EDT 2009
On Fri, Apr 17, 2009 at 7:17 PM, Jean-Claude Neveu
<jcn-france1972 at pobox.com> wrote:
> Hello,
>
> 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
search() instead.***
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.
Cheers,
Chris
--
I have a blog:
http://blog.rebertia.com
More information about the Python-list
mailing list