Lines Matching refs:match
39 self.assertEqual(re.match('a*', 'xxx').span(0), (0, 0))
40 self.assertEqual(re.match('a*', 'xxx').span(), (0, 0))
41 self.assertEqual(re.match('x*', 'xxxa').span(0), (0, 3))
42 self.assertEqual(re.match('x*', 'xxxa').span(), (0, 3))
43 self.assertIsNone(re.match('a+', 'xxx'))
122 self.assertRaises(ValueError, re.match, pattern, 'A', re.I)
261 self.assertEqual(re.match('a', 'a').groups(), ())
262 self.assertEqual(re.match('(a)', 'a').groups(), ('a',))
263 self.assertEqual(re.match(r'(a)', 'a').group(0), 'a')
264 self.assertEqual(re.match(r'(a)', 'a').group(1), 'a')
265 self.assertEqual(re.match(r'(a)', 'a').group(1, 1), ('a', 'a'))
268 self.assertEqual(pat.match('a').groups(), ('a', 'a', None, None))
269 self.assertEqual(pat.match('b').groups(), ('b', None, 'b', None))
270 self.assertEqual(pat.match('ac').groups(), ('a', 'a', None, 'c'))
271 self.assertEqual(pat.match('bc').groups(), ('b', None, 'b', 'c'))
272 self.assertEqual(pat.match('bc').groups(""), ('b', "", 'b', 'c'))
275 m = re.match('(a)', 'a')
282 self.assertEqual(pat.match('a').group(1, 2, 3), ('a', None, None))
283 self.assertEqual(pat.match('b').group('a1', 'b2', 'c3'),
285 self.assertEqual(pat.match('ac').group(1, 'b2', 3), ('a', None, 'c'))
288 self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
290 self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups(),
292 self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'))
293 self.assertIsNone(re.match('^(\()?([^()]+)(?(1)\))$', '(a'))
294 self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups(),
296 self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
298 self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
300 self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
305 self.assertEqual(p.match('abc').groups(),
307 self.assertEqual(p.match('ad').groups(),
309 self.assertIsNone(p.match('abd'))
310 self.assertIsNone(p.match('ac'))
314 self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a|').groups(),
316 self.assertEqual(re.match(r'^(\|)?([^()]+)\1?$', 'a').groups(),
318 self.assertIsNone(re.match(r'^(\|)?([^()]+)\1$', 'a|'))
319 self.assertIsNone(re.match(r'^(\|)?([^()]+)\1$', '|a'))
320 self.assertEqual(re.match(r'^(?:(a)|c)(\1)$', 'aa').groups(),
322 self.assertEqual(re.match(r'^(?:(a)|c)(\1)?$', 'c').groups(),
326 self.assertEqual(re.match('(?P<first>first) (?P<second>second)',
331 self.assertEqual(re.match("(?P<first>first) (?P<second>second)",
337 self.assertIsNone(re.match("^(\w){1}$", "abc"))
338 self.assertIsNone(re.match("^(\w){1}?$", "abc"))
339 self.assertIsNone(re.match("^(\w){1,2}$", "abc"))
340 self.assertIsNone(re.match("^(\w){1,2}?$", "abc"))
342 self.assertEqual(re.match("^(\w){3}$", "abc").group(1), "c")
343 self.assertEqual(re.match("^(\w){1,3}$", "abc").group(1), "c")
344 self.assertEqual(re.match("^(\w){1,4}$", "abc").group(1), "c")
345 self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
346 self.assertEqual(re.match("^(\w){3}?$", "abc").group(1), "c")
347 self.assertEqual(re.match("^(\w){1,3}?$", "abc").group(1), "c")
348 self.assertEqual(re.match("^(\w){1,4}?$", "abc").group(1), "c")
349 self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
351 self.assertIsNone(re.match("^x{1}$", "xxx"))
352 self.assertIsNone(re.match("^x{1}?$", "xxx"))
353 self.assertIsNone(re.match("^x{1,2}$", "xxx"))
354 self.assertIsNone(re.match("^x{1,2}?$", "xxx"))
356 self.assertTrue(re.match("^x{3}$", "xxx"))
357 self.assertTrue(re.match("^x{1,3}$", "xxx"))
358 self.assertTrue(re.match("^x{1,4}$", "xxx"))
359 self.assertTrue(re.match("^x{3,4}?$", "xxx"))
360 self.assertTrue(re.match("^x{3}?$", "xxx"))
361 self.assertTrue(re.match("^x{1,3}?$", "xxx"))
362 self.assertTrue(re.match("^x{1,4}?$", "xxx"))
363 self.assertTrue(re.match("^x{3,4}?$", "xxx"))
365 self.assertIsNone(re.match("^x{}$", "xxx"))
366 self.assertTrue(re.match("^x{}$", "x{}"))
369 self.assertEqual(re.match("(a)", "a").pos, 0)
370 self.assertEqual(re.match("(a)", "a").endpos, 1)
371 self.assertEqual(re.match("(a)", "a").string, "a")
372 self.assertEqual(re.match("(a)", "a").regs, ((0, 1), (0, 1)))
373 self.assertTrue(re.match("(a)", "a").re)
412 self.assertTrue(re.match(r"\b", "abc"))
416 self.assertFalse(re.match(r"\B", "abc"))
435 self.assertEqual(re.match(u(r"([\u2222\u2223])"),
437 self.assertEqual(re.match(u(r"([\u2222\u2223])"),
440 self.assertEqual(re.match(r, unichr(0xff01), re.UNICODE).group(), unichr(0xff01))
445 self.assertTrue(r.match('1000'))
446 self.assertTrue(r.match('9999'))
449 self.assertEqual(re.match("a.b", "a\nb", re.DOTALL).group(0),
451 self.assertEqual(re.match("a.*b", "a\n\nb", re.DOTALL).group(0),
455 self.assertEqual(re.match("(a(?=\s[^a]))", "a b").group(1), "a")
456 self.assertEqual(re.match("(a(?=\s[^a]*))", "a b").group(1), "a")
457 self.assertEqual(re.match("(a(?=\s[abc]))", "a b").group(1), "a")
458 self.assertEqual(re.match("(a(?=\s[abc]*))", "a bc").group(1), "a")
459 self.assertEqual(re.match(r"(a)(?=\s\1)", "a a").group(1), "a")
460 self.assertEqual(re.match(r"(a)(?=\s\1*)", "a aa").group(1), "a")
461 self.assertEqual(re.match(r"(a)(?=\s(abc|a))", "a a").group(1), "a")
463 self.assertEqual(re.match(r"(a(?!\s[^a]))", "a a").group(1), "a")
464 self.assertEqual(re.match(r"(a(?!\s[abc]))", "a d").group(1), "a")
465 self.assertEqual(re.match(r"(a)(?!\s\1)", "a b").group(1), "a")
466 self.assertEqual(re.match(r"(a)(?!\s(abc|a))", "a b").group(1), "a")
469 self.assertTrue(re.match(r'(a)b(?=\1)a', 'aba'))
470 self.assertIsNone(re.match(r'(a)b(?=\1)c', 'abac'))
472 self.assertTrue(re.match(r'(?P<g>a)b(?=(?P=g))a', 'aba'))
473 self.assertIsNone(re.match(r'(?P<g>a)b(?=(?P=g))c', 'abac'))
475 self.assertTrue(re.match(r'(?:(a)|(x))b(?=(?(2)x|c))c', 'abc'))
476 self.assertIsNone(re.match(r'(?:(a)|(x))b(?=(?(2)c|x))c', 'abc'))
477 self.assertTrue(re.match(r'(?:(a)|(x))b(?=(?(2)x|c))c', 'abc'))
478 self.assertIsNone(re.match(r'(?:(a)|(x))b(?=(?(1)b|x))c', 'abc'))
479 self.assertTrue(re.match(r'(?:(a)|(x))b(?=(?(1)c|x))c', 'abc'))
481 self.assertTrue(re.match(r'(a)b(?=(?(2)x|c))(c)', 'abc'))
482 self.assertIsNone(re.match(r'(a)b(?=(?(2)b|x))(c)', 'abc'))
483 self.assertTrue(re.match(r'(a)b(?=(?(1)c|x))(c)', 'abc'))
486 self.assertTrue(re.match(r'ab(?<=b)c', 'abc'))
487 self.assertIsNone(re.match(r'ab(?<=c)c', 'abc'))
488 self.assertIsNone(re.match(r'ab(?<!b)c', 'abc'))
489 self.assertTrue(re.match(r'ab(?<!c)c', 'abc'))
504 self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
505 self.assertEqual(re.match("abc", u"ABC", re.I).group(0), "ABC")
506 self.assertEqual(re.match(r"(a\s[^a])", "a b", re.I).group(1), "a b")
507 self.assertEqual(re.match(r"(a\s[^a]*)", "a bb", re.I).group(1), "a bb")
508 self.assertEqual(re.match(r"(a\s[abc])", "a b", re.I).group(1), "a b")
509 self.assertEqual(re.match(r"(a\s[abc]*)", "a bb", re.I).group(1), "a bb")
510 self.assertEqual(re.match(r"((a)\s\2)", "a a", re.I).group(1), "a a")
511 self.assertEqual(re.match(r"((a)\s\2*)", "a aa", re.I).group(1), "a aa")
512 self.assertEqual(re.match(r"((a)\s(abc|a))", "a a", re.I).group(1), "a a")
513 self.assertEqual(re.match(r"((a)\s(abc|a)*)", "a aa", re.I).group(1), "a aa")
517 self.assertTrue(re.match(ur'K', u(r'\u212a'), re.U | re.I))
518 self.assertTrue(re.match(ur'k', u(r'\u212a'), re.U | re.I))
519 self.assertTrue(re.match(u(r'\u212a'), u'K', re.U | re.I))
520 self.assertTrue(re.match(u(r'\u212a'), u'k', re.U | re.I))
522 self.assertTrue(re.match(ur'S', u(r'\u017f'), re.U | re.I))
523 self.assertTrue(re.match(ur's', u(r'\u017f'), re.U | re.I))
524 self.assertTrue(re.match(u(r'\u017f'), u'S', re.U | re.I))
525 self.assertTrue(re.match(u(r'\u017f'), u's', re.U | re.I))
528 self.assertTrue(re.match(r'[19A]', 'A', re.I))
529 self.assertTrue(re.match(r'[19a]', 'a', re.I))
530 self.assertTrue(re.match(r'[19a]', 'A', re.I))
531 self.assertTrue(re.match(r'[19A]', 'a', re.I))
533 self.assertTrue(re.match(ur'[19A]', u'A', re.U | re.I))
534 self.assertTrue(re.match(ur'[19a]', u'a', re.U | re.I))
535 self.assertTrue(re.match(ur'[19a]', u'A', re.U | re.I))
536 self.assertTrue(re.match(ur'[19A]', u'a', re.U | re.I))
538 self.assertTrue(re.match(u(r'[19K]'), u(r'\u212a'), re.U | re.I))
539 self.assertTrue(re.match(u(r'[19k]'), u(r'\u212a'), re.U | re.I))
540 self.assertTrue(re.match(u(r'[19\u212a]'), u'K', re.U | re.I))
541 self.assertTrue(re.match(u(r'[19\u212a]'), u'k', re.U | re.I))
543 self.assertTrue(re.match(ur'[19S]', u(r'\u017f'), re.U | re.I))
544 self.assertTrue(re.match(ur'[19s]', u(r'\u017f'), re.U | re.I))
545 self.assertTrue(re.match(u(r'[19\u017f]'), u'S', re.U | re.I))
546 self.assertTrue(re.match(u(r'[19\u017f]'), u's', re.U | re.I))
550 self.assertTrue(re.match(r'[9-a]', '_', re.I))
551 self.assertIsNone(re.match(r'[9-A]', '_', re.I))
552 self.assertTrue(re.match(r'[\xc0-\xde]', '\xd7', re.I))
553 self.assertIsNone(re.match(r'[\xc0-\xde]', '\xf7', re.I))
554 self.assertTrue(re.match(r'[\xe0-\xfe]', '\xf7',re.I))
555 self.assertIsNone(re.match(r'[\xe0-\xfe]', '\xd7', re.I))
557 self.assertTrue(re.match(u(r'[9-a]'), u(r'_'), re.U | re.I))
558 self.assertIsNone(re.match(u(r'[9-A]'), u(r'_'), re.U | re.I))
559 self.assertTrue(re.match(u(r'[\xc0-\xde]'),
561 self.assertIsNone(re.match(u(r'[\xc0-\xde]'),
563 self.assertTrue(re.match(u(r'[\xe0-\xfe]'),
565 self.assertIsNone(re.match(u(r'[\xe0-\xfe]'),
567 self.assertTrue(re.match(u(r'[\u0430-\u045f]'),
569 self.assertTrue(re.match(u(r'[\u0430-\u045f]'),
571 self.assertTrue(re.match(u(r'[\u0400-\u042f]'),
573 self.assertTrue(re.match(u(r'[\u0400-\u042f]'),
576 self.assertTrue(re.match(u(r'[\U00010428-\U0001044f]'),
578 self.assertTrue(re.match(u(r'[\U00010428-\U0001044f]'),
580 self.assertTrue(re.match(u(r'[\U00010400-\U00010427]'),
582 self.assertTrue(re.match(u(r'[\U00010400-\U00010427]'),
586 self.assertTrue(re.match(ur'[J-M]', u(r'\u212a'), re.U | re.I))
587 self.assertTrue(re.match(ur'[j-m]', u(r'\u212a'), re.U | re.I))
588 self.assertTrue(re.match(u(r'[\u2129-\u212b]'), u'K', re.U | re.I))
589 self.assertTrue(re.match(u(r'[\u2129-\u212b]'), u'k', re.U | re.I))
591 self.assertTrue(re.match(ur'[R-T]', u(r'\u017f'), re.U | re.I))
592 self.assertTrue(re.match(ur'[r-t]', u(r'\u017f'), re.U | re.I))
593 self.assertTrue(re.match(u(r'[\u017e-\u0180]'), u'S', re.U | re.I))
594 self.assertTrue(re.match(u(r'[\u017e-\u0180]'), u's', re.U | re.I))
597 self.assertEqual(re.match(r"(\s)", " ").group(1), " ")
606 self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
607 self.assertEqual(re.match("abc", u"ABC", re.I).group(0), "ABC")
617 def assertMatch(self, pattern, text, match=None, span=None, argument
618 matcher=re.match):
619 if match is None and span is None:
621 match = text
623 elif match is None or span is None:
628 self.assertEqual(m.group(), match)
706 self.assertTrue(re.match(r"\%03o" % i, chr(i)))
707 self.assertTrue(re.match(r"\%03o0" % i, chr(i)+"0"))
708 self.assertTrue(re.match(r"\%03o8" % i, chr(i)+"8"))
709 self.assertTrue(re.match(r"\x%02x" % i, chr(i)))
710 self.assertTrue(re.match(r"\x%02x0" % i, chr(i)+"0"))
711 self.assertTrue(re.match(r"\x%02xz" % i, chr(i)+"z"))
712 self.assertRaises(re.error, re.match, "\911", "")
716 self.assertTrue(re.match(r"[\%03o]" % i, chr(i)))
717 self.assertTrue(re.match(r"[\%03o0]" % i, chr(i)))
718 self.assertTrue(re.match(r"[\%03o8]" % i, chr(i)))
719 self.assertTrue(re.match(r"[\x%02x]" % i, chr(i)))
720 self.assertTrue(re.match(r"[\x%02x0]" % i, chr(i)))
721 self.assertTrue(re.match(r"[\x%02xz]" % i, chr(i)))
722 self.assertRaises(re.error, re.match, "[\911]", "")
725 self.assertEqual(re.match(r'(a)|(b)', 'b').start(1), -1)
726 self.assertEqual(re.match(r'(a)|(b)', 'b').end(1), -1)
727 self.assertEqual(re.match(r'(a)|(b)', 'b').span(1), (-1, -1))
731 self.assertIsNone(re.match(r'(a)?a','a').lastindex)
732 self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
733 self.assertEqual(re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup, 'a')
734 self.assertEqual(re.match("(?P<a>a(b))", "ab").lastgroup, 'a')
735 self.assertEqual(re.match("((a))", "a").lastindex, 1)
746 self.assertEqual(re.match('.*?c', 10000*'ab'+'cd').end(0), 20001)
747 self.assertEqual(re.match('.*?cd', 5000*'ab'+'c'+5000*'ab'+'cde').end(0),
749 self.assertEqual(re.match('.*?cd', 20000*'abc'+'de').end(0), 60001)
762 self.assertEqual(re.match('(x)*', 50000*'x').group(1), 'x')
763 self.assertEqual(re.match('(x)*y', 50000*'x'+'y').group(1), 'x')
764 self.assertEqual(re.match('(x)*?y', 50000*'x'+'y').group(1), 'x')
768 self.assertIsNone(re.match(r'(?:a?)*y', 'z'))
769 self.assertIsNone(re.match(r'(?:a?)+y', 'z'))
770 self.assertIsNone(re.match(r'(?:a?){2,}y', 'z'))
771 self.assertIsNone(re.match(r'(?:a?)*?y', 'z'))
772 self.assertIsNone(re.match(r'(?:a?)+?y', 'z'))
773 self.assertIsNone(re.match(r'(?:a?){2,}?y', 'z'))
799 self.assertEqual(re.match(r'((.%s):)?z'%op, 'z').groups(),
801 self.assertEqual(re.match(r'((.%s):)?z'%op, 'a:z').groups(),
806 self.assertEqual(re.match('^((a)|b)*', 'abc').groups(),
808 self.assertEqual(re.match('^(([ab])|c)*', 'abc').groups(),
810 self.assertEqual(re.match('^((d)|[ab])*', 'abc').groups(),
812 self.assertEqual(re.match('^((a)c|[ab])*', 'abc').groups(),
814 self.assertEqual(re.match('^((a)|b)*?c', 'abc').groups(),
816 self.assertEqual(re.match('^(([ab])|c)*?d', 'abcd').groups(),
818 self.assertEqual(re.match('^((d)|[ab])*?c', 'abc').groups(),
820 self.assertEqual(re.match('^((a)c|[ab])*?c', 'abc').groups(),
825 self.assertEqual(re.match('(a)(?:(?=(b)*)c)*', 'abb').groups(),
827 self.assertEqual(re.match('(a)((?!(b)*))*', 'abb').groups(),
835 self.assertIsNone(pat.match("xyz"))
879 self.assertEqual(re.match('^\d$', x, re.UNICODE).group(0), x)
888 self.assertIsNone(re.match('^\d$', x, re.UNICODE))
898 self.assertIsNone(re.compile("bla").match(a))
899 self.assertEqual(re.compile("").match(a).groups(), ())
908 q = p.match(lower_char)
912 q = p.match(upper_char)
916 q = p.match(lower_char)
920 q = p.match(upper_char)
924 q = p.match(lower_char)
928 q = p.match(upper_char)
931 self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char))
932 self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))
996 self.assertEqual(re.match(r".{65535}", string).span(), (0, 65535))
997 self.assertEqual(re.match(r".{,65535}", string).span(), (0, 65535))
998 self.assertEqual(re.match(r".{65535,}?", string).span(), (0, 65535))
999 self.assertEqual(re.match(r".{65536}", string).span(), (0, 65536))
1000 self.assertEqual(re.match(r".{,65536}", string).span(), (0, 65536))
1001 self.assertEqual(re.match(r".{65536,}?", string).span(), (0, 65536))
1015 self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string))
1016 self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(),
1018 self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string))
1050 m = r.match("xyyzy")
1088 pat.match(string='abracadabra', pos=7, endpos=10).span(), (7, 9))
1098 self.assertEqual(re.match("(foo)", "foo").group(1L), "foo")
1099 self.assertRaises(IndexError, re.match("", "").group, sys.maxint + 1)
1121 self.assertTrue(re.match(b'\xc5\xe5', b'\xc5\xe5', re.L|re.I))
1122 self.assertTrue(re.match(b'\xc5', b'\xe5', re.L|re.I))
1123 self.assertTrue(re.match(b'\xe5', b'\xc5', re.L|re.I))
1124 self.assertTrue(re.match(b'(?Li)\xc5\xe5', b'\xc5\xe5'))
1125 self.assertTrue(re.match(b'(?Li)\xc5', b'\xe5'))
1126 self.assertTrue(re.match(b'(?Li)\xe5', b'\xc5'))
1130 self.assertTrue(re.match(b'\xc5\xe5', b'\xc5\xe5', re.L|re.I))
1131 self.assertIsNone(re.match(b'\xc5', b'\xe5', re.L|re.I))
1132 self.assertIsNone(re.match(b'\xe5', b'\xc5', re.L|re.I))
1133 self.assertTrue(re.match(b'(?Li)\xc5\xe5', b'\xc5\xe5'))
1134 self.assertIsNone(re.match(b'(?Li)\xc5', b'\xe5'))
1135 self.assertIsNone(re.match(b'(?Li)\xe5', b'\xc5'))