This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sjmachin
Recipients sjmachin
Date 2011-02-12.23:19:55
SpamBayes Score 0.00063599023
Marked as misclassified No
Message-id <1297552798.48.0.889043344562.issue11204@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-02-12 23:19:58sjmachinsetrecipients: + sjmachin
2011-02-12 23:19:58sjmachinsetmessageid: <1297552798.48.0.889043344562.issue11204@psf.upfronthosting.co.za>
2011-02-12 23:19:56sjmachinlinkissue11204 messages
2011-02-12 23:19:55sjmachincreate