Martin von Loewis loewis at
Tue Mar 20 21:29:31 CET 2001

msoulier at (Michael P. Soulier) writes:

> >no, it's not.  read the documentation again.
>     That answer was so warm and informative I'd think this was
> comp.lang.perl.misc. 

You have to take two things into account:

a) you were critizing the author of the regex code (in its sre
   incarnation), and
b) this is regular expressions, which seem be unfriendly by nature
   (which perhaps had an influence on comp.lang.perl.misc as well :-)
c) Fredrik spent quite some time getting all the "start of line"
   and "start of string" cases right. It was difficult to write,
   so it should be difficult to understand :-)

Well, that's three things :-)

>     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.

I find match extremely useful, and I never ever use search. The reason
is that I use regular expressions for tokenization of languages with a
formal syntax. There, I don't care whether the point where I look for
the next token happens to be the start of a line - but I absolutely
must make sure that any match I get is at the current position (or
else there is a syntax error).

Please have a look at the undocumented sre.Scanner class for an
example of using match in a loop.

> 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.

Well, maybe you should phrase your question in a way that encourages
discussion. You've stated 

# 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.

quite factually, implying that there can't be any possible other use
or difference. The manual would have told you that there is a
difference, so if you had read the manual, you could have shown in the
article that you know the difference, and ask the question that you
were really interested in "Why would anybody ever use match?" :-)


More information about the Python-list mailing list