From: Raymond Hettinger Date: Sun, 26 Sep 2004 18:56:44 +0000 (+0000) Subject: Make the regex pattern easier to read, understand, and modify X-Git-Tag: v2.4b1~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55593c3ef530ea01b1cfb1f7c81ee34fd994d0ef;p=python Make the regex pattern easier to read, understand, and modify by factoring out the common prefix (the delimiter). --- diff --git a/Lib/string.py b/Lib/string.py index 623eb0edab..7371c915a1 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -101,10 +101,12 @@ class _multimap: class _TemplateMetaclass(type): pattern = r""" - (?P%(delim)s{2}) | # Escape sequence of two delimiters - %(delim)s(?P%(id)s) | # delimiter and a Python identifier - %(delim)s{(?P%(id)s)} | # delimiter and a braced identifier - (?P%(delim)s) # Other ill-formed delimiter exprs + %(delim)s(?: + (?P%(delim)s) | # Escape sequence of two delimiters + (?P%(id)s) | # delimiter and a Python identifier + {(?P%(id)s)} | # delimiter and a braced identifier + (?P) # Other ill-formed delimiter exprs + ) """ def __init__(cls, name, bases, dct):