예제 #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
파일: reader.py 프로젝트: 1989tianlong/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] != ';']
예제 #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") == [":", "::", ":::"]