Regex for Python 2.7

John Machin sjmachin at lexicon.net
Sun Jan 25 01:10:28 CET 2009


On Jan 25, 7:23 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> Some time ago I discovered this difference between regular expressions
> in Python and Perl:
>
> Python
>
>         \A matches at start of string
>         \Z matches at end of string
>
> Perl
>
>         \A matches at start of string
>         \Z matches before terminal newline or at end of string
>         \z matches at end of string
>
> In Perl \A == ^ and \Z == $ in single-string mode, but in Python \A == ^
> and \Z != $ in single-string mode.
>
> Obviously, changing Python's \Z to match Perl's could break existing
> code. \z could be added, but with the opposite meaning to Perl's:
>
>         Python's \Z == Perl's \z
>         Python's \z == Perl's \Z
>
> Would that be confusing?
>
> Any suggests welcome.

IIRC there was an exchange some years ago where the perl guy (Larry?)
admitted that he goofed and the consensus was that what Python had
done was better.



More information about the Python-list mailing list