I have a python application that should handle custom regular expressions. For performance reasons, I want to disable capture groups and backlinks.
My idea is to use another regular expression to make sure the user-defined regular expression does not contain any names or unnamed groups, such as:
def validate_user_regex(pattern): if re.match('[^\\\]\((?:\?P).*?[^\\\]\)', pattern) is not None: return False return True
Although I think my idea might work for capturing groups, I'm not sure if this will prevent all kinds of backlinks. So are there any smarter ways to prevent capturing groups and backlinks in regular expressions?
source share