re.match

Michael P. Soulier msoulier at nortelnetworks.com
Tue Mar 20 13:22:05 EST 2001


On Tue, 20 Mar 2001 17:29:23 GMT, Fredrik Lundh <fredrik at pythonware.com>
wrote:
>Michael P. Soulier wrote:
>>     Hey people. Could someone explain the purpose of the match function in
>>     the re module? If it's only difference from search is to match at the
>>     beginning of the line, why does it exist? That's what the ^ in the
>>     regexp is for.
>
>no, it's not.  read the documentation again.

    That answer was so warm and informative I'd think this was
comp.lang.perl.misc. 

---quote---
Note that match may differ from search using a regular expression beginning
with "^": "^" matches only at the start of the string, or in MULTILINE mode
also immediately following a newline. The ``match'' operation succeeds only if
the pattern matches at the start of the string regardless of mode, or at the
starting position given by the optional pos argument regardless of whether a
newline precedes it. 
---end quote---

    The difference is apparently multiline mode. My point was that it doesn't
seem to offer enough of a difference to justify going against standard regexp
syntax and ignore the ^ character. It is misleading, IMHO, and Python seems to
be all about being easy to learn. Thus being misleading is not beneficial. 

    Again, thanks for the extremely helpful response. If someone would
actually care to have a discussion with me on this so that I might understand
the reasons why this was done, please do so. As always, one asks questions not
to simply annoy, but to learn. There was a time when Usenet was a good place
to do that. 

    Cheers,

    Mike

-- 
Michael P. Soulier, TD12, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"With sufficient thrust, pigs fly just fine. However, this is not necessarily a
good idea. It is hard to be sure where they are going to land, and it could be
dangerous sitting under them as they fly overhead." -- RFC 1925
Nortel Linux User's Group Ottawa: (internal) http://nlug.ca.nortel.com



More information about the Python-list mailing list