Skip to content

Instantly share code, notes, and snippets.

@jonathanmorley
Forked from jpsim/answers.md
Last active November 16, 2022 17:42
  • Star 64 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jonathanmorley/8058871 to your computer and use it in GitHub Desktop.
Best possible answers collected so far for [Regex golf](http://regex.alf.nu/). === WARNING: SPOILERS ===

See Also:

Normal

Level Score Regex Credit
Warmup 207 foo
Anchors 208 k$
Ranges 202 ^[a-f]*$
Backrefs 201 (...).*\1 gorhill (HN)
Abba 195 ^(?!.*(.)\1)|ef BeniaminK (GH)
A man, a plan 177 ^(.)[^p].*\1$ hyp0 (HN)
Prime 286 ^(?!(..+)\1+$) josephlord (HN)
Four 199 (.)(.\1){3} chrismorgan (HN) / MereInterest (HN)
Order 199 ^.{5}[^e]?$ ekke (HN)
Triples 596 00($|3|6|9|12|15)|4.2|.1.+4|55|.17 alexandrosm (GH)
Glob 397 ai|c$|^p|[bcnrw][bnopr] nwellnhof (HN)
Balance 454 .{37}|^(<(..(?!<.>$))*>)*$ Davidebyzero (GH)
Powers 93 ^(?!(.(..)+)\1*$) plby (GH)
Long count 256 ((.+)0\2+1){8} Davidebyzero (GH)
Alphabetical 317 .r.{32}r|a.{10}te|n.n.. alexandrosm (GH)
Powers 2 88 ^(?!((xxx)+x|xx|)\1*$) muxrwc (GH)
Total 4075
Subtraction 180 ^(.+)(.+) - \1 = \2$ jonathanmorley (GH)
Typist 181 ^[adresbtcfxzgvw]+$ jonathanmorley (GH)

Hard Mode

Level Score Regex Credit
Warmup 207 foo
Anchors 206 ick$ Davidebyzero (GH)
Ranges 202 ^[a-f]*$
Backrefs 201 (...).*\1 gorhill (HN)
Abba 193 ^(?!.*(.)(.)\2\1) chingjun (HN) / josephlord (HN)
A man, a plan 150 ^(.?)(.?)(.?)(.?)(.?)(.?).?\6\5\4\3\2\1$ jonathanmorley (GH)
Prime 284 ^(?!(xx+)\1+$)xx Davidebyzero (GH)
Four 199 (.)(.\1){3} chrismorgan (HN) / MereInterest (HN)
Order 156 ^a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*$ Davidebyzero (GH)
Triples 524 (?=((.*?[147]){3})*((.*?[147]|){2}))(?=((.*?[258]){3})*((.*?[258]|){2}))^.*$(\3\7|(?!\3|\7)\4\8|(?!\4|\8)) teukon (GH)
Glob 297 ai|c$|^p|[bcnrw][bnopr] nwellnhof (HN)
Balance 443 ^(<(<(<(<(<(<(<>)*>)*>)*>)*>)*>)*>)*$ gkucmierz (GH)
Powers 93 ^(?!(.(..)+)\1*$) plby (GH)
Long count 239 ^((?=(\S*)0).{4} (?=\2[1]))+1+$ Davidebyzero (GH)
Alphabetical 282 ^(?!.*\b(.*)(e|(n|r|(s|t))).* \1(a|(?!\3)[en]|(?!\4)[rs])) teukon (GH)
Powers 2 -12 ^(?!((xxx)+x|xx|)\1*$) muxrwc (GH)
Total 3664
Subtraction 180 ^(.+)(.+) - \1 = \2$ jonathanmorley (GH)
Typist 180 ^[adresbtcfxzgvwq]+$ jonathanmorley (GH)
@The-Snide-Sniper
Copy link

The-Snide-Sniper commented May 8, 2016

Glob - Hard (341): ^(.*)(?=.*( .* \1))(\2|\*(.*)(\2.+\4|\*(.*)(\2.+\4.+\6|\*(.*)\2.+\4.+\6.+\8)))$
Long Count - Hard (245): ^((\d*)01* (?=\2(1)))*1*$
Powers 2 - Hard (76): x{16385}|^(?!(xx(xx)?(xxx)*)\1*$)x
Subtraction - Normal, Subtraction - Hard (182): ^(.+)(.+)- \2= \1
Typist - Normal, Typist - Hard (189): ^[^h-puy]*$

@micsthepick
Copy link

micsthepick commented Jun 7, 2016

No-one thought of these yet?
Tic-tac-toe: (Hard or robust) (168) (X|O)(\1|..(\1|.\1.|..\1..)..)\1
Powers 2: (Hard/robust) (89) ^((x+)\2(?=\2$)|x$)+$

@teukon
Copy link

teukon commented Sep 9, 2016

Addition (robust) (177): ^(.*)(.*)(.*) = \3\2\1$ (credit to Davidebyzero)
Tic-tac-toe (robust) (169): (\w)(\1|..(\1|.\1.|..\1..)..)\1 (nice work micsthepick!)

Each of the bonus problems can be done with fewer than 40 characters. Most can be done using no more than 30 characters.

@eromoe
Copy link

eromoe commented Apr 19, 2017

Any idea about this https://alf.nu/RegexGolf#accesstoken=Da3Q/rKFFqZwSic2o5Rt ?

It never ends – $ not allowed

Match all of these…
✔fu
✔tofu
✔snafu
and none of these…
✕futz
✕fusillade
✕functional
✕discombobulated

@altair21
Copy link

For It never ends - $ not allowed:
u\b

@tmzh
Copy link

tmzh commented May 19, 2017

A man, a plan: ^(.)(.).*\2\1$

@depperm
Copy link

depperm commented Jul 27, 2017

Abba: ^(?!(.)+\1)|.u

@Davidebyzero
Copy link

I've updated Best known Regex Golf solutions. The current Classic level set is fully covered. It's now in table format, including full credits and date-time stamps, a history of gradual improvements for most of the levels, and some extra bonus information.

I have intentionally not updated the Teukon level set solutions compilation, nor posted one for Holiday, as with the release of functioning high score lists in the newly brought back Regex Golf site, to do so would further taint the high scores with people who simply Google it and copy the solutions. This is not an ideal situation by any means, as I'd really like for everyone to be able to benefit from this knowledge if they so desire, but given the way the on-site high score lists currently function, I see no alternative. Having date-time stamps in the on-site high score lists would be a good start towards fixing this problem.

@837951602
Copy link

Subtraction ^(x+)(.+)- \2= \1$, no full space

@KorayUlusan
Copy link

New level: It never ends – $ not allowed
3 chars: u\b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment