Validating regexp

Skip Montanaro skip.montanaro at gmail.com
Tue Aug 8 13:00:11 EDT 2017


> I have an app that allows users to enter regexps for db searching.
> When a user enters an invalid one (e.g. 'A|B|' is one I just saw) it
> causes downstream issues. I'd like to flag it at entry time.

Just call re.compile(...) on it and catch any exceptions, modulo
caveats about operating with unvalidated user input.

Skip



More information about the Python-list mailing list