Last active
May 2, 2020 04:33
-
-
Save scturtle/8066503 to your computer and use it in GitHub Desktop.
Answer to regex golf http://regex.alf.nu/
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
plain = r'foo' | |
anchor = r'k$' | |
ranges = r'^[a-f]*$' | |
backrefs = r'(...).*\1' | |
abba = (r'^(?!' # don't ( | |
r'.*(.)(.)\2\1.*' # parttern like abba | |
r'$)') # ) select | |
plan = r'^(.)(.).*\2\1$' | |
prime = (r'^(?!' # don't ( | |
r'(xx+?)\1+' # parttern that 'x' group (length > 1) is repeated | |
r'$)') # ) select | |
four = r'(.).\1.\1.\1' | |
order = r'^[a-h]*[i-z]*$' # cheat a bit, try to find a good split spot | |
triples = 'link: http://quaxio.com/triple/' # tough, see this blog that | |
# construct a FSM first | |
glob = (r'^(\w*) matches \1$|' # no star | |
r'^(\w*)\*(\w*) matches \2\w+\3$|' # one star | |
r'^(\w*)\*(\w*)\*(\w*) matches \4\w+\5\w+\6$|' # two star | |
r'^(\w*)\*(\w*)\*(\w*)\*(\w*) matches \7\w+\8\w+\9\w+\10$') | |
glob2 = (r'^(\*?)(\w*)(\*?)(\w*)(\*?)(\w*)' | |
r' .* ' # matches | |
r'((.(?!\1))+|\1)\2((.(?!\3))+|\3)\4((.(?!\5))+|\5)\6$') | |
# ((.(?!\1))+|\1) is used to conditionally match .+ if \1 if found (via @hadrel) | |
balance = r'^(<(<(<(<(<(<(<>)*>)*>)*>)*>)*>)*>)*$' | |
powers = (r'^(?!' # don't ( | |
r'(x(xx)+)' # parttern that odd number of 'x' | |
r'\1*' # is repeated | |
r'$)') # ) select (via @plby) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
10 Bonus Levels