def test_complex_regex(): regex = re.compile(r'(\d[.-])?\d{3,}[.-]\d{3,}[.-]\d{4,}') s = """ never call the number 1-800-666-1337. instead, you sould call the number 333-3737-13 but actually, that number sucks, so call "9-373-185-7242" or really just hit me up at777.777.7777 """ matches = list(find_regex_in_string(regex=regex, s=s)) assert len(matches) == 3 for m in matches: assert m.re.pattern == regex.pattern assert m.re.flags == regex.flags assert m.string == s assert matches[0].group() == '1-800-666-1337' assert matches[1].group() == '9-373-185-7242' assert matches[2].group() == '777.777.7777'
def test_regex_only(): regex = re.compile('test') assert list(find_regex_in_string(regex=regex)) == []
def test_no_arguments(): assert find_regex_in_string() == []
def test_string_only(): assert find_regex_in_string(s='test') == []