re Challenge: More Compact?

Tim Peters tim.one at home.com
Mon Jul 16 02:23:25 EDT 2001


[John Machin, on $ matching before or after a terminating newline]
> ...
> I shall enter a bug report and leave it up to the powers_that_be to
> decide whether to change the behaviour or section 4.2.1 of the
> documentation.

The behavior can't be changed:  this was deliberate, for compatibility with
Perl5 regexps.  Mounds of code would break if it changed.

> To answer Tim's question, yes it bothers me ... the solution of course
> always when you want to validate that the pattern matches the whole
> string (and not some leading substring) is to have \Z at the end of
> your pattern (not $).

Careful!  This is where Python and Perl parted company, and again
deliberately.  Guido and Larry argued about this near the end of '97, and
Python refused to let \Z match before a terminating newline; Perl does.
Perl later grew \z to do what Python's (but not Perl's) \Z does.

Three years later, in

http://archive.develooper.com/perl6-language-regex@perl.org/msg00358.html

Tom Christiansen wrote:

    This is an annoying gotcha.  Larry once said that he wished
    he had made \Z do what \z now does.  One would like $ to (be
    able to) mean "ONLY AT END OF STRING".

Heh -- *everyone* should listen to Guido <wink>.





More information about the Python-list mailing list