Message128472
A pattern like r"b{1,3}\Z" matches "b", "bb", and "bbb", as expected. There is no documentation of the behaviour of r"b{1, 3}\Z" -- it matches the LITERAL TEXT "b{1, 3}" in normal mode and "b{1,3}" in verbose mode.
# paste the following at the interactive prompt:
pat = r"b{1, 3}\Z"
bool(re.match(pat, "bb")) # False
bool(re.match(pat, "b{1, 3}")) # True
bool(re.match(pat, "bb", re.VERBOSE)) # False
bool(re.match(pat, "b{1, 3}", re.VERBOSE)) # False
bool(re.match(pat, "b{1,3}", re.VERBOSE)) # True
Suggested change, in decreasing order of preference:
(1) Ignore leading/trailing spaces when parsing the m and n components of {m,n}
(2) Raise an exception if the exact syntax is not followed
(3) Document the existing behaviour
Note: deliberately matching the literal text would be expected to be done by escaping the left brace:
pat2 = r"b\{1, 3}\Z"
bool(re.match(pat2, "b{1, 3}")) # True
and this is not prevented by the suggested changes. |
|
Date |
User |
Action |
Args |
2011-02-12 23:19:58 | sjmachin | set | recipients:
+ sjmachin |
2011-02-12 23:19:58 | sjmachin | set | messageid: <1297552798.48.0.889043344562.issue11204@psf.upfronthosting.co.za> |
2011-02-12 23:19:56 | sjmachin | link | issue11204 messages |
2011-02-12 23:19:55 | sjmachin | create | |
|