129129# public symbols
130130__all__ = [
131131 "match" , "fullmatch" , "search" , "sub" , "subn" , "split" ,
132- "findall" , "finditer" , "compile" , "purge" , "escape" ,
132+ "findall" , "finditer" , "compile" , "purge" , "template" , " escape" ,
133133 "error" , "Pattern" , "Match" , "A" , "I" , "L" , "M" , "S" , "X" , "U" ,
134134 "ASCII" , "IGNORECASE" , "LOCALE" , "MULTILINE" , "DOTALL" , "VERBOSE" ,
135135 "UNICODE" , "NOFLAG" , "RegexFlag" ,
@@ -148,6 +148,8 @@ class RegexFlag:
148148 MULTILINE = M = _compiler .SRE_FLAG_MULTILINE # make anchors look for newline
149149 DOTALL = S = _compiler .SRE_FLAG_DOTALL # make dot match newline
150150 VERBOSE = X = _compiler .SRE_FLAG_VERBOSE # ignore whitespace and comments
151+ # sre extensions (experimental, don't rely on these)
152+ TEMPLATE = T = _compiler .SRE_FLAG_TEMPLATE # disable backtracking
151153 DEBUG = _compiler .SRE_FLAG_DEBUG # dump pattern after compilation
152154 __str__ = object .__str__
153155 _numeric_repr_ = hex
@@ -229,6 +231,10 @@ def purge():
229231 _cache .clear ()
230232 _compile_repl .cache_clear ()
231233
234+ def template (pattern , flags = 0 ):
235+ "Compile a template pattern, returning a Pattern object"
236+ return _compile (pattern , flags | T )
237+
232238# SPECIAL_CHARS
233239# closing ')', '}' and ']'
234240# '-' (a range in character set)
0 commit comments