Regex for Python 2.7

MRAB google at mrabarnett.plus.com
Sat Jan 24 18:51:31 EST 2009


Gabriel Genellina wrote:
 > En Sat, 24 Jan 2009 18:23:51 -0200, MRAB <google at mrabarnett.plus.com>
 > escribió:
 >
 >> 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.
 >
 > Why do you want the two to be equivalent? Isn't a good thing that you
 > have both alternatives (\Z and $)? Use whichever is adequate in each 
case.
 >
Python's \Z is equivalent to Perl's \z, but there's no equivalent to 
Perl's \Z in multi-line mode.



More information about the Python-list mailing list