示例#1
0
文件: test_re.py 项目: charred/pypy
 def test_re_findall(self):
     assert re.findall(":+", "abc") == []
     assert re.findall(":+", "a:b::c:::d") == [":", "::", ":::"]
     assert re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"]
     assert re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
                                                            (":", ":"),
                                                            (":", "::")]
示例#2
0
def rsre_example():
    # scan through string looking for the first location where the regular
    # expression pattern produces a match
    print re.search('x*', 'axx').span(0)

    # if zero or more characters at the beginning of string match the regular
    # expression pattern
    print re.match('a+', 'xxx')

    # split string by the occurrences of pattern
    print re.split(":", ":a:b::c")

    # return all non-overlapping matches of pattern in string, as a list of
    # strings
    print re.findall(":+", "a:b::c:::d")
示例#3
0
def tokenize(str):
    re_str = "[\s,]*(~@|[\[\]{}()'`~^@]|\"(?:[\\\\].|[^\\\\\"])*\"|;.*|[^\s\[\]{}()'\"`@,;]+)"
    if IS_RPYTHON:
        tok_re = re_str
    else:
        tok_re = re.compile(re_str)
    return [t for t in re.findall(tok_re, str) if t[0] != ';']
示例#4
0
文件: reader.py 项目: zzhgithub/mal
def tokenize(str):
    re_str = "[\s,]*(~@|[\[\]{}()'`~^@]|\"(?:[\\\\].|[^\\\\\"])*\"?|;.*|[^\s\[\]{}()'\"`@,;]+)"
    if IS_RPYTHON:
        tok_re = re_str
    else:
        tok_re = re.compile(re_str)
    return [t for t in re.findall(tok_re, str) if t[0] != ';']
示例#5
0
 def f(i):
     if i:
         s = "aaaaaa"
     else:
         s = "caaaaa"
     print rsre_re.match("(a|b)aa", s)
     print rsre_re.match("a{4}", s)
     print rsre_re.search("(a|b)aa", s)
     print rsre_re.search("a{4}", s)
     for x in rsre_re.findall("(a|b)a", s):  print x
     for x in rsre_re.findall("a{2}", s):    print x
     for x in rsre_re.finditer("(a|b)a", s): print x
     for x in rsre_re.finditer("a{2}", s):   print x
     for x in rsre_re.split("(a|b)a", s):    print x
     for x in rsre_re.split("a{2}", s):      print x
     return 0
示例#6
0
def rsre_example():
    # simulate scanf, %s - %d errors, %d warnings
    print re.search(r"(\S+) - (\d+) errors, (\d+) warnings",
                    "/usr/sbin/sendmail - 0 errors, 4 warnings").groups()

    # making a phone book
    text = """Ross McFluff: 834.345.1254 155 Elm Street
Ronald Heathmore: 892.345.3428 436 Finley Avenue
Frank Burger: 925.541.7625 662 South Dogwood Way
Heather Albrecht: 548.326.4584 919 Park Place"""
    entries = re.split("\n+", text)
    print[re.split(":? ", entry, 4) for entry in entries]

    # finding all adverbs
    text = "He was carefully disguised but captured quickly by police."
    print re.findall(r"\w+ly", text)
示例#7
0
 def f(i):
     if i:
         s = "aaaaaa"
     else:
         s = "caaaaa"
     print rsre_re.match("(a|b)aa", s)
     print rsre_re.match("a{4}", s)
     print rsre_re.search("(a|b)aa", s)
     print rsre_re.search("a{4}", s)
     for x in rsre_re.findall("(a|b)a", s):
         print x
     for x in rsre_re.findall("a{2}", s):
         print x
     for x in rsre_re.finditer("(a|b)a", s):
         print x
     for x in rsre_re.finditer("a{2}", s):
         print x
     for x in rsre_re.split("(a|b)a", s):
         print x
     for x in rsre_re.split("a{2}", s):
         print x
     return 0
示例#8
0
文件: test_re.py 项目: charred/pypy
 def test_bug_117612(self):
     assert re.findall(r"(a|(b))", "aba") == (
                      [("a", ""),("b", "b"),("a", "")])
示例#9
0
文件: test_re.py 项目: Darriall/pypy
 def test_bug_117612(self):
     py.test.skip("findall() returning groups is not RPython")
     assert re.findall(r"(a|(b))", "aba") == (
                      [("a", ""),("b", "b"),("a", "")])
示例#10
0
文件: test_re.py 项目: Darriall/pypy
 def test_re_findall_2(self):
     py.test.skip("findall() returning groups is not RPython")
     assert re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
                                                            (":", ":"),
                                                            (":", "::")]
示例#11
0
 def test_bug_117612(self):
     py.test.skip("findall() returning groups is not RPython")
     assert re.findall(r"(a|(b))", "aba") == ([("a", ""), ("b", "b"),
                                               ("a", "")])
示例#12
0
 def test_re_findall_2(self):
     py.test.skip("findall() returning groups is not RPython")
     assert re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""), (":", ":"),
                                                    (":", "::")]
示例#13
0
 def test_re_findall(self):
     assert re.findall(":+", "abc") == []
     assert re.findall(":+", "a:b::c:::d") == [":", "::", ":::"]
     assert re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"]