[docs] [issue13899] re pattern r"[\A]" should work like "A" but matches nothing. Ditto B and Z.

Ezio Melotti report at bugs.python.org
Tue Jan 31 14:13:10 CET 2012

Ezio Melotti <ezio.melotti at gmail.com> added the comment:

The rule 1 makes sense, but it's not entirely obvious (people might consider bBaAzZ special too).

The "normal Python rules for backslash escapes but revert to the C behaviour of stripping the \ from unrecognised escapes" is not obvious either, and from r'[\A]' people might expect:
  1) same as \A, (beginning of the string);
  2) a letter 'A';
  3) a '\' or a letter 'A' (especially if they write it as '[\\A]');

This is why I suggested to raise an error (and refuse the temptation to guess), but on the other hand, if you consider 'A' a "normal" letter like 'C', having an error for \A would be incoherent.
It would have been better if \C raised an error too (I don't see why that would appear in a regex, since re.escape doesn't escape C and the user has no reason to add the \), but now it's too late for that.


Python tracker <report at bugs.python.org>

More information about the docs mailing list