Last active
September 23, 2018 17:55
-
-
Save bashkirtsevich/71d53106a63afbf890066b05629c41c7 to your computer and use it in GitHub Desktop.
RegEx word permute
This file contains hidden or 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 groupby | |
| def make_regexp(word): | |
| return "^{}[{}]+$".format( | |
| "".join( | |
| "(?!(.*{}){{{}}})".format(char, freq) | |
| for char, freq in map( | |
| lambda item: (item[0], sum(1 for _ in item[1]) + 1), | |
| groupby(sorted(word)) | |
| ) | |
| ), | |
| "".join(set(word)) | |
| ) | |
| print(make_regexp("творец")) |
This file contains hidden or 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
| sigleline | |
| ^(?!(.*а){4})(?!(.*г){2})(?!(.*ж){2})(?!(.*з){2})(?!(.*и){2})(?!(.*к){2})(?!(.*л){2})[зажигалка]+$ | |
| multiline | |
| ^(?!(.*а){4}) | |
| (?!(.*г){2}) | |
| (?!(.*ж){2}) | |
| (?!(.*з){2}) | |
| (?!(.*и){2}) | |
| (?!(.*к){2}) | |
| (?!(.*л){2})[зажигалка]+$ |
This file contains hidden or 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
| w='зажигалка'; echo $w | sed 's/./&\n/g;s/.$//' | sort | uniq -c | \ | |
| sed -r 's/^\s*([0-9]+)\s*(.)$/echo \\(?!\\(.*\2\\)\\{$((\1+1))\\}\\)/e;1s/^/^/;$s/$/['$w']+$/' | \ | |
| sed ':a;N;s/\n//;ta' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment