我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sre_parse.Pattern()。
def __init__(self, rules, flags=0): pattern = Pattern() pattern.flags = flags if sys.version_info < (3, 0): pattern.groups = len(rules) + 1 _og = pattern.opengroup pattern.opengroup = lambda n: _og(n and '%s\x00%s' % (name, n) or n) self.rules = [] subpatterns = [] for group, (name, regex) in enumerate(rules, 1): last_group = pattern.groups - 1 subpatterns.append( SubPattern(pattern, [ (SUBPATTERN, (group, parse(regex, flags, pattern))), ])) self.rules.append((name, last_group, pattern.groups - 1)) self._scanner = sre_compile( SubPattern(pattern, [(BRANCH, (None, subpatterns))])).scanner
def __init__(self, lexicon, flags=0): from sre_constants import BRANCH, SUBPATTERN self.lexicon = lexicon # combine phrases into a compound pattern p = [] s = sre_parse.Pattern() s.flags = flags for phrase, action in lexicon: gid = s.opengroup() p.append(sre_parse.SubPattern(s, [ (SUBPATTERN, (gid, 0, 0, sre_parse.parse(phrase, flags))), ])) s.closegroup(gid, p[-1]) p = sre_parse.SubPattern(s, [(BRANCH, (None, p))]) self.scanner = sre_compile.compile(p)
def __init__(self, lexicon, flags=0): from sre_constants import BRANCH, SUBPATTERN self.lexicon = lexicon # combine phrases into a compound pattern p = [] s = sre_parse.Pattern() s.flags = flags for phrase, action in lexicon: p.append(sre_parse.SubPattern(s, [ (SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))), ])) s.groups = len(p)+1 p = sre_parse.SubPattern(s, [(BRANCH, (None, p))]) self.scanner = sre_compile.compile(p)
def __init__(self, lexicon, flags=0): from sre_constants import BRANCH, SUBPATTERN self.lexicon = lexicon # combine phrases into a compound pattern p = [] s = sre_parse.Pattern() s.flags = flags for phrase, action in lexicon: gid = s.opengroup() p.append(sre_parse.SubPattern(s, [ (SUBPATTERN, (gid, sre_parse.parse(phrase, flags))), ])) s.closegroup(gid, p[-1]) p = sre_parse.SubPattern(s, [(BRANCH, (None, p))]) self.scanner = sre_compile.compile(p)