Created
October 29, 2015 18:31
-
-
Save tiborsimon/8cf9e3d6c8ce2ca36ce8 to your computer and use it in GitHub Desktop.
Regular expression generator for mandatory characters in arbitrary order.
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
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