How to capture an exception raised by a Python Regular expression?

When the match method is implemented, if it turns out that there are no matches, then None is returned. There are no functions in the re module that throw up an exception when the list or matches is empty

exception re.error

Exception raised when a string passed to one of the functions here is not a valid regular expression (for example, it might contain unmatched parentheses) or when some other error occurs during compilation or matching. It is never an error if a string contains no match for a pattern.

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started