Catch exception for invalid regular expressions.