Created
June 27, 2016 18:46
-
-
Save brad-anton/f5c190d8d54445d1eecb1f6e2e2ae44d to your computer and use it in GitHub Desktop.
Example lookup table implementation for regex generator
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
# Create mappings for every character, for instance: | |
s=['s','5','z','es','2'] | |
alphabet={ 's':s } | |
def get_permutations(self, letter): | |
try: | |
permutations = alphabet[letter] | |
except KeyError: # The letter is not in alphabet | |
permutations = letter | |
regex = '[' | |
for p in permutations[:-1]: | |
regex += '{0}|'.format(p) | |
regex += '{0}]'.format(permutations[-1]) | |
return regex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment