示例#1
0
 def test_escape(self):
     reg = dfareg.compile(r"a\c")
     self.assert_(reg.matches(r"ac"))
     self.assert_(not reg.matches(r"a\c"))
     reg = dfareg.compile(r"a\\c")
     self.assert_(reg.matches(r"a\c"))
     self.assert_(not reg.matches(r"ac"))
示例#2
0
def main():
    s = r"(ABC*|abc*)*"
    reg = dfareg.compile(s)
    print("正規表現: " + s)
    print("ABC: " + str(reg.matches("ABC")))
    print("ABBC: " + str(reg.matches("ABBC")))
    print("abcccAB: " + str(reg.matches("abcccAB")))
示例#3
0
 def test_syntax_error(self):
     import sys
     for regexp in ['ab(cd', 'e(*)f', ')h', 'i|*', '*']:
         err = None
         try:
             reg = dfareg.compile(regexp)
         except Exception, e:
             err = e
         self.assert_(str(err) == 'syntax error')
示例#4
0
 def test_empty_select(self):
     reg = dfareg.compile(r"a(b|)")
     self.assert_(reg.matches(r"ab"))
     self.assert_(reg.matches(r"a"))
     self.assert_(not reg.matches(r"abb"))
示例#5
0
 def test_japanese2(self):
     reg = dfareg.compile(ur"ww*|\(笑\)")
     self.assert_(reg.matches(u"(笑)"))
     self.assert_(reg.matches(u"www"))
     self.assert_(not reg.matches(u"笑"))
示例#6
0
 def test_japanese1(self):
     reg = dfareg.compile(ur"山田(太|一|次|三)郎")
     self.assert_(reg.matches(u"山田太郎"))
     self.assert_(reg.matches(u"山田三郎"))
     self.assert_(not reg.matches("山田郎"))
示例#7
0
 def test_normal(self):
     reg = dfareg.compile(r"(p(erl|ython|hp)|ruby)")
     self.assert_(reg.matches("python"))
     self.assert_(reg.matches("ruby"))
     self.assert_(not reg.matches("VB"))