re.fullmatch() vs re.findall()
re.fullmatch() and re.findall() are both Python Regex Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. re.fullmatch(): Checks if the entire string matches the regex pattern. Its syntax is re.fullmatch(pattern, string, flags=0), and it returns match object or None re.findall(): Returns all non-overlapping matches as a list of strings or tuples. Its syntax is re.findall(pattern, string, flags=0), and it returns list of strings or tuples Example of re.fullmatch(): re.fullmatch(r"\\d+", "123") # Match (entire string)
re.fullmatch(r"\\d+", "123abc") # None. Example of re.findall(): re.findall(r"\\d+", "a1b2c3") # ["1", "2", "3"]
re.findall(r"(\\w)(\\d)", "a1b2") # [("a","1"), ("b","2")]. Read the full references for re.fullmatch() and re.findall() to see parameters, edge cases, and example code side by side. Other Regex Module APIs worth comparing: re.search(), re.match(), re.finditer(), re.sub(), re.subn(), re.split().