本文整理汇总了Python中sre_parse.expand_template函数的典型用法代码示例。如果您正苦于以下问题:Python expand_template函数的具体用法?Python expand_template怎么用?Python expand_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expand_template函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _expand
def _expand(self, m, template):
# XXX This code depends on internals of the regular expression
# engine! There's no standard API to do a substitution when you
# have already found the match. One should be added.
# The solution here is designed to be backwards compatible
# with previous Python versions, e.g. 1.5.2.
# XXX This dynamic test should be done only once.
if getattr(re, "engine", "pre") == "pre":
return re.pcre_expand(m, template)
else: # sre
# XXX This import should be avoidable...
import sre_parse
# XXX This parses the template over and over...
ptemplate = sre_parse.parse_template(template, m.re)
return sre_parse.expand_template(ptemplate, m)
示例2: expand_sub
def expand_sub(string, template, debug=0, mode='all') :
""" Given a regular expression and a replacement string, generate expansions of
the regular expression and for each one return it and its transformation
as applied by the replacement string.
string : regular expression to expand
template : transformation to apply to each regular expression
mode : can take 3 values
all : return all possible shortest strings that the regular expression
would match
first : return the first string that all would return
random : return one random string that the regular expression would match
"""
pattern = sre_parse.parse(string, flags=sre_parse.SRE_FLAG_VERBOSE)
pattern.mode = mode
template = sre_parse.parse_template(template, pattern)
if debug :
print pattern
print template
for s in _iterate(pattern, pattern.data, MatchObj(pattern, "")) :
s.patient = 0
yield (s.string, sre_parse.expand_template(template, s))
示例3: filter
def filter(match, template=template):
return sre_parse.expand_template(template, match)
示例4: _expand
def _expand(pattern, match, template):
# internal: match.expand implementation hook
template = sre_parse.parse_template(template, pattern)
return sre_parse.expand_template(template, match)
示例5: expand
def expand(self, template) :
template = sre_parse.parse_template(template, self.pattern)
return sre_parse.expand_template(template, self)
示例6: filter
def filter(match, template = template): #@ReservedAssignment
return sre_parse.expand_template(template, match)