本文整理汇总了Python中pypy.rlib.rsre.rsre_re.match函数的典型用法代码示例。如果您正苦于以下问题:Python match函数的具体用法?Python match怎么用?Python match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了match函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_bug_527371
def test_bug_527371(self):
# bug described in patches 527371/672491
assert re.match(r'(a)?a','a').lastindex == None
assert re.match(r'(a)(b)?b','ab').lastindex == 1
assert re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup == 'a'
assert re.match("(?P<a>a(b))", "ab").lastgroup == 'a'
assert re.match("((a))", "a").lastindex == 1
开发者ID:gorakhargosh,项目名称:pypy,代码行数:7,代码来源:test_re.py
示例2: test_bug_448951
def test_bug_448951(self):
# bug 448951 (similar to 429357, but with single char match)
# (Also test greedy matches.)
for op in '','?','*':
assert re.match(r'((.%s):)?z'%op, 'z').groups() == (
(None, None))
assert re.match(r'((.%s):)?z'%op, 'a:z').groups() == (
('a:', 'a'))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_re.py
示例3: test_getlower
def test_getlower(self):
import _sre
assert _sre.getlower(ord('A'), 0) == ord('a')
assert _sre.getlower(ord('A'), re.LOCALE) == ord('a')
assert _sre.getlower(ord('A'), re.UNICODE) == ord('a')
assert re.match("abc", "ABC", re.I).group(0) == "ABC"
assert re.match("abc", u"ABC", re.I).group(0) == "ABC"
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_re.py
示例4: test_re_escape
def test_re_escape(self):
p=""
for i in range(0, 256):
p = p + chr(i)
assert re.match(re.escape(chr(i)), chr(i)) is not None
assert re.match(re.escape(chr(i)), chr(i)).span() == (0,1)
pat=re.compile(re.escape(p))
assert pat.match(p) is not None
assert pat.match(p).span() == (0,256)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:10,代码来源:test_re.py
示例5: test_bug_418626
def test_bug_418626(self):
# bugs 418626 at al. -- Testing Greg Chapman's addition of op code
# SRE_OP_MIN_REPEAT_ONE for eliminating recursion on simple uses of
# pattern '*?' on a long string.
assert re.match('.*?c', 10000*'ab'+'cd').end(0) == 20001
assert re.match('.*?cd', 5000*'ab'+'c'+5000*'ab'+'cde').end(0) == (
20003)
assert re.match('.*?cd', 20000*'abc'+'de').end(0) == 60001
# non-simple '*?' still used to hit the recursion limit, before the
# non-recursive scheme was implemented.
assert re.search('(a|b)*?c', 10000*'ab'+'cd').end(0) == 20001
开发者ID:gorakhargosh,项目名称:pypy,代码行数:11,代码来源:test_re.py
示例6: test_search_star_plus
def test_search_star_plus(self):
assert re.search('x*', 'axx').span(0) == (0, 0)
assert re.search('x*', 'axx').span() == (0, 0)
assert re.search('x+', 'axx').span(0) == (1, 3)
assert re.search('x+', 'axx').span() == (1, 3)
assert re.search('x', 'aaa') == None
assert re.match('a*', 'xxx').span(0) == (0, 0)
assert re.match('a*', 'xxx').span() == (0, 0)
assert re.match('x*', 'xxxa').span(0) == (0, 3)
assert re.match('x*', 'xxxa').span() == (0, 3)
assert re.match('a+', 'xxx') == None
开发者ID:gorakhargosh,项目名称:pypy,代码行数:11,代码来源:test_re.py
示例7: test_ignore_case
def test_ignore_case(self):
assert re.match(r"(a\s[^a])", "a b", re.I).group(1) == "a b"
assert re.match(r"(a\s[^a]*)", "a bb", re.I).group(1) == "a bb"
assert re.match(r"(a\s[abc])", "a b", re.I).group(1) == "a b"
assert re.match(r"(a\s[abc]*)", "a bb", re.I).group(1) == "a bb"
assert re.match(r"((a)\s\2)", "a a", re.I).group(1) == "a a"
assert re.match(r"((a)\s\2*)", "a aa", re.I).group(1) == "a aa"
assert re.match(r"((a)\s(abc|a))", "a a", re.I).group(1) == "a a"
assert re.match(r"((a)\s(abc|a)*)", "a aa", re.I).group(1) == "a aa"
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_re.py
示例8: test_re_match
def test_re_match(self):
assert re.match('a', 'a').groups() == ()
assert re.match('(a)', 'a').groups() == ('a',)
assert re.match(r'(a)', 'a').group(0) == 'a'
assert re.match(r'(a)', 'a').group(1) == 'a'
assert re.match(r'(a)', 'a').group(1, 1) == ('a', 'a')
pat = re.compile('((a)|(b))(c)?')
assert pat.match('a').groups() == ('a', 'a', None, None)
assert pat.match('b').groups() == ('b', None, 'b', None)
assert pat.match('ac').groups() == ('a', 'a', None, 'c')
assert pat.match('bc').groups() == ('b', None, 'b', 'c')
assert pat.match('bc').groups("") == ('b', "", 'b', 'c')
# A single group
m = re.match('(a)', 'a')
assert m.group(0) == 'a'
assert m.group(0) == 'a'
assert m.group(1) == 'a'
assert m.group(1, 1) == ('a', 'a')
pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
assert pat.match('a').group(1, 2, 3) == ('a', None, None)
assert pat.match('b').group('a1', 'b2', 'c3') == (
(None, 'b', None))
assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c')
开发者ID:gorakhargosh,项目名称:pypy,代码行数:26,代码来源:test_re.py
示例9: test_sre_character_class_literals
def test_sre_character_class_literals(self):
for i in [0, 8, 16, 32, 64, 127, 128, 255]:
assert re.match(r"[\%03o]" % i, chr(i)) != None
assert re.match(r"[\%03o0]" % i, chr(i)) != None
assert re.match(r"[\%03o8]" % i, chr(i)) != None
assert re.match(r"[\x%02x]" % i, chr(i)) != None
assert re.match(r"[\x%02x0]" % i, chr(i)) != None
assert re.match(r"[\x%02xz]" % i, chr(i)) != None
raises(re.error, re.match, "[\911]", "")
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_re.py
示例10: test_sre_character_literals
def test_sre_character_literals(self):
for i in [0, 8, 16, 32, 64, 127, 128, 255]:
assert re.match(r"\%03o" % i, chr(i)) != None
assert re.match(r"\%03o0" % i, chr(i)+"0") != None
assert re.match(r"\%03o8" % i, chr(i)+"8") != None
assert re.match(r"\x%02x" % i, chr(i)) != None
assert re.match(r"\x%02x0" % i, chr(i)+"0") != None
assert re.match(r"\x%02xz" % i, chr(i)+"z") != None
raises(re.error, re.match, "\911", "")
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:test_re.py
示例11: test_bug_725106
def test_bug_725106(self):
# capturing groups in alternatives in repeats
assert re.match('^((a)|b)*', 'abc').groups() == (
('b', 'a'))
assert re.match('^(([ab])|c)*', 'abc').groups() == (
('c', 'b'))
assert re.match('^((d)|[ab])*', 'abc').groups() == (
('b', None))
assert re.match('^((a)c|[ab])*', 'abc').groups() == (
('b', None))
assert re.match('^((a)|b)*?c', 'abc').groups() == (
('b', 'a'))
assert re.match('^(([ab])|c)*?d', 'abcd').groups() == (
('c', 'b'))
assert re.match('^((d)|[ab])*?c', 'abc').groups() == (
('b', None))
assert re.match('^((a)c|[ab])*?c', 'abc').groups() == (
('b', None))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:18,代码来源:test_re.py
示例12: test_re_groupref
def test_re_groupref(self):
assert re.match(r'^(\|)?([^()]+)\1$', '|a|').groups() == (
('|', 'a'))
assert re.match(r'^(\|)?([^()]+)\1?$', 'a').groups() == (
(None, 'a'))
assert re.match(r'^(\|)?([^()]+)\1$', 'a|') == None
assert re.match(r'^(\|)?([^()]+)\1$', '|a') == None
assert re.match(r'^(?:(a)|c)(\1)$', 'aa').groups() == (
('a', 'a'))
assert re.match(r'^(?:(a)|c)(\1)?$', 'c').groups() == (
(None, None))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:11,代码来源:test_re.py
示例13: test_re_groupref_exists
def test_re_groupref_exists(self):
assert re.match('^(\()?([^()]+)(?(1)\))$', '(a)').groups() == (
('(', 'a'))
assert re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups() == (
(None, 'a'))
assert re.match('^(\()?([^()]+)(?(1)\))$', 'a)') == None
assert re.match('^(\()?([^()]+)(?(1)\))$', '(a') == None
assert re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups() == (
('a', 'b'))
assert re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups() == (
(None, 'd'))
assert re.match('^(?:(a)|c)((?(1)|d))$', 'cd').groups() == (
(None, 'd'))
assert re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups() == (
('a', ''))
# Tests for bug #1177831: exercise groups other than the first group
p = re.compile('(?P<g1>a)(?P<g2>b)?((?(g2)c|d))')
assert p.match('abc').groups() == (
('a', 'b', 'c'))
assert p.match('ad').groups() == (
('a', None, 'd'))
assert p.match('abd') == None
assert p.match('ac') == None
开发者ID:gorakhargosh,项目名称:pypy,代码行数:24,代码来源:test_re.py
示例14: test_stack_overflow
def test_stack_overflow(self):
# nasty cases that used to overflow the straightforward recursive
# implementation of repeated groups.
assert re.match('(x)*', 50000*'x').group(1) == 'x'
assert re.match('(x)*y', 50000*'x'+'y').group(1) == 'x'
assert re.match('(x)*?y', 50000*'x'+'y').group(1) == 'x'
开发者ID:gorakhargosh,项目名称:pypy,代码行数:6,代码来源:test_re.py
示例15: test_groupdict
def test_groupdict(self):
assert re.match('(?P<first>first) (?P<second>second)',
'first second').groupdict() == (
{'first':'first', 'second':'second'})
开发者ID:gorakhargosh,项目名称:pypy,代码行数:4,代码来源:test_re.py
示例16: test_bug_113254
def test_bug_113254(self):
assert re.match(r'(a)|(b)', 'b').start(1) == -1
assert re.match(r'(a)|(b)', 'b').end(1) == -1
assert re.match(r'(a)|(b)', 'b').span(1) == (-1, -1)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:4,代码来源:test_re.py
示例17: test_repeat_minmax
def test_repeat_minmax(self):
assert re.match("^(\w){1}$", "abc") == None
assert re.match("^(\w){1}?$", "abc") == None
assert re.match("^(\w){1,2}$", "abc") == None
assert re.match("^(\w){1,2}?$", "abc") == None
assert re.match("^(\w){3}$", "abc").group(1) == "c"
assert re.match("^(\w){1,3}$", "abc").group(1) == "c"
assert re.match("^(\w){1,4}$", "abc").group(1) == "c"
assert re.match("^(\w){3,4}?$", "abc").group(1) == "c"
assert re.match("^(\w){3}?$", "abc").group(1) == "c"
assert re.match("^(\w){1,3}?$", "abc").group(1) == "c"
assert re.match("^(\w){1,4}?$", "abc").group(1) == "c"
assert re.match("^(\w){3,4}?$", "abc").group(1) == "c"
assert re.match("^x{1}$", "xxx") == None
assert re.match("^x{1}?$", "xxx") == None
assert re.match("^x{1,2}$", "xxx") == None
assert re.match("^x{1,2}?$", "xxx") == None
assert re.match("^x{3}$", "xxx") != None
assert re.match("^x{1,3}$", "xxx") != None
assert re.match("^x{1,4}$", "xxx") != None
assert re.match("^x{3,4}?$", "xxx") != None
assert re.match("^x{3}?$", "xxx") != None
assert re.match("^x{1,3}?$", "xxx") != None
assert re.match("^x{1,4}?$", "xxx") != None
assert re.match("^x{3,4}?$", "xxx") != None
assert re.match("^x{}$", "xxx") == None
assert re.match("^x{}$", "x{}") != None
开发者ID:gorakhargosh,项目名称:pypy,代码行数:31,代码来源:test_re.py
示例18: test_bug_725149
def test_bug_725149(self):
# mark_stack_base restoring before restoring marks
assert re.match('(a)(?:(?=(b)*)c)*', 'abb').groups() == (
('a', None))
assert re.match('(a)((?!(b)*))*', 'abb').groups() == (
('a', None, None))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:6,代码来源:test_re.py
示例19: test_non_consuming
def test_non_consuming(self):
assert re.match("(a(?=\s[^a]))", "a b").group(1) == "a"
assert re.match("(a(?=\s[^a]*))", "a b").group(1) == "a"
assert re.match("(a(?=\s[abc]))", "a b").group(1) == "a"
assert re.match("(a(?=\s[abc]*))", "a bc").group(1) == "a"
assert re.match(r"(a)(?=\s\1)", "a a").group(1) == "a"
assert re.match(r"(a)(?=\s\1*)", "a aa").group(1) == "a"
assert re.match(r"(a)(?=\s(abc|a))", "a a").group(1) == "a"
assert re.match(r"(a(?!\s[^a]))", "a a").group(1) == "a"
assert re.match(r"(a(?!\s[abc]))", "a d").group(1) == "a"
assert re.match(r"(a)(?!\s\1)", "a b").group(1) == "a"
assert re.match(r"(a)(?!\s(abc|a))", "a b").group(1) == "a"
开发者ID:gorakhargosh,项目名称:pypy,代码行数:13,代码来源:test_re.py
示例20: test_anyall
def test_anyall(self):
assert re.match("a.b", "a\nb", re.DOTALL).group(0) == (
"a\nb")
assert re.match("a.*b", "a\n\nb", re.DOTALL).group(0) == (
"a\n\nb")
开发者ID:gorakhargosh,项目名称:pypy,代码行数:5,代码来源:test_re.py
注:本文中的pypy.rlib.rsre.rsre_re.match函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论