Validating regexp

Peter Heitzer peter.heitzer at rz.uni-regensburg.de
Wed Aug 9 06:13:47 EDT 2017


Larry Martell <larry.martell at gmail.com> wrote:
>On Tue, Aug 8, 2017 at 12:51 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> On Wed, Aug 9, 2017 at 2:37 AM, Larry Martell <larry.martell at gmail.com> wrote:
>>> Anyone have any code or know of any packages for validating a regexp?
>>>
>>> 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.
>>
>> re.compile()? Although I'm not sure that 'A|B|' is actually invalid.
>> But re.compile("(") throws.

>Yeah, it does not throw for 'A|B|' - but mysql chokes on it with empty
>subexpression for regexp' I'd like to flag it before it gets to SQL.

Then you need to do a real sql query with the regex and check if it throws.

-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heitzer at rz.uni-regensburg.de



More information about the Python-list mailing list