Skip to content

Instantly share code, notes, and snippets.

@tiborsimon
Created October 29, 2015 18:31
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 tiborsimon/8cf9e3d6c8ce2ca36ce8 to your computer and use it in GitHub Desktop.
Save tiborsimon/8cf9e3d6c8ce2ca36ce8 to your computer and use it in GitHub Desktop.
Regular expression generator for mandatory characters in arbitrary order.
from itertools import permutations
import re
def generate_mandatory_arbitrary(content):
pattern_string = '('
for p in permutations(content):
pattern_string += '(.*'
for i in p:
pattern_string += '{}.*'.format(i)
pattern_string += ')|'
return pattern_string[:-1] + ')'
print(generate_mandatory_arbitrary('abc'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment