I have a python application which needs to process user submitted regular expressions. Because of performance considerations i want to forbid capturing groups and back references.
My idea is to use another regular expression to verify that the user submitted regex does not contain any named or unnamed group captures like this:
def validate_user_regex(pattern):
if re.match('[^\\\]\((?:\?P).*?[^\\\]\)', pattern) is not None:
return False
return True
While i think my idea may work for capturing groups, i am not sure if this would prevent all kinds of back references. So are there any smarter ways to prevent capturing groups and back references in regular expressions?