Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brad-anton/f5c190d8d54445d1eecb1f6e2e2ae44d to your computer and use it in GitHub Desktop.
Save brad-anton/f5c190d8d54445d1eecb1f6e2e2ae44d to your computer and use it in GitHub Desktop.
Example lookup table implementation for regex generator
# 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