regex puzzle

Alex Martelli aleax at aleax.it
Wed Nov 6 10:14:39 EST 2002


Mike Brown wrote:
   ...
> seems to give me what I want: r'\A(?!\n)(.+)?\Z'  ... thanks for getting
> me on the right track!

(.+)?

is basically the same thing as

(.*)

right?


> I'm not sure I understand the difference between ^$ and \A\Z, but the

\A is always start-of-string and nothing else, \Z always end-of-string
and nothing else.  ^ and $, depending on the setting of re.M or not,
may also match around a \n; $ I believe always matches just before a
trailing \n in particular, with or without re.M.

> (?!\n) makes sense.

Yes, negative-lookahead is quite handy sometimes.


Alex




More information about the Python-list mailing list