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"))
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")))
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')
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"))
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"笑"))
def test_japanese1(self): reg = dfareg.compile(ur"山田(太|一|次|三)郎") self.assert_(reg.matches(u"山田太郎")) self.assert_(reg.matches(u"山田三郎")) self.assert_(not reg.matches("山田郎"))
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"))