re.match

Michael P. Soulier msoulier at nortelnetworks.com
Tue Mar 20 14:38:54 EST 2001


On Tue, 20 Mar 2001 10:53:16 -0800, Ken Seehof <kens at sightreader.com> wrote:
>re.match tests whether or not a string -matches- a regular expression.
>re.search -searches- a string for the first occurrence of a regular
>expression.

    And hence the non-intuitive aspect of it. If you include an anchor in your
regexp, ie. ^ or $, then the definition of a match is such that the pattern
matches at the beginning and/or end of the line respectively. If you do not
include anchors, then by the definition of the regexp syntax, the entire line
should be searched. 
    Now, it appears that re.match has special capability with respect to
multi-line strings, but again, this is non-standard regexp syntax, and hence
non-intuitive. 

    No biggy, but surprising compared to every other implementation of regexps
that I've seen. 

    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