inconsistency? Re: Boy do REs ever suck sometimes...
Tim Peters
tim.one at home.com
Fri Oct 5 15:55:24 EDT 2001
[Roman Suzi]
> I think the following behaviour of re module is incorrect:
>
> >>> re.match("^(123)($)", "123\n").group(1, 2)
> ('123', '')
>
> If $ matches \n, then why doesn't it include it to the
> group?
Because the antecedent is incorrect: $ is a "zero-width assertion", like \b
and ^: if it matches it all, it matches a null string. The only useful
behavior of zero-width assertions is to make a path of the match attempt
fail if the asserted condition doesn't hold.
More information about the Python-list
mailing list