Last active
May 15, 2021 00:55
-
-
Save havron/ed1026df7bbc84a00b5f3db61d241e44 to your computer and use it in GitHub Desktop.
Check the regexes of a file split by '"validation": '
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def sanitize(regex): | |
if regex.startswith('r"'): | |
regex = regex[2:] | |
elif regex.startswith('"'): | |
regex = regex[1:] | |
if regex.endswith('"'): | |
regex = regex[:-1] | |
return regex | |
def compiles(regex): | |
if 'EMAIL_RE' in regex: | |
return True | |
try: | |
return bool(re.compile(regex)) | |
except re.error: | |
return False | |
return False | |
if __name__ == '__main__': | |
with open('validations.txt', 'r') as f: | |
lines = [line.strip(' ,\n').split('"validation": ') for line in f] | |
for line in lines: | |
regex = sanitize(line[1]) | |
if not compiles(regex): | |
print(line[0], regex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment