Regex Golf Solutions

正则表达式练习(玩耍)网站 Regex Golf

使用指南:点开右边的每一道题,可以看到两个 list。写出一个正则表达式,使得可以匹配(不要求完全匹配)左边列的每一个,不能匹配右边任意一个。

  • Classic
    • Warmup: foo
    • Anchors: k$
    • It never ends: u\b or u(?!.)
    • Ranges: ^[a-f]*$
    • Backrefs: (...).*\1
    • Abba: ^(?!.*(.)(.)\2\1)
    • A man, a plan: ^(.)(.).*\2\1$
    • Prime: ^(?!(xx+)\1+$)
    • Four: (.)(.\1){3}
    • Order: ^.{5}[^e]?$(cheat),^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*$
    • Triples: ^([0369]|[258][0369]*[147]|([147]|[258][0369]*[258])([0369]|[147][0369]*[258])*([258]|[147][0369]*[147]))*$explanation
    • Glob: ^(\*?)(\w*)(\*?)(\w*)(\*?)(\w*) .* ((?!\1).+|\1)\2((?!\3).+|\3)\4((?!\5).+|\5)\6$
    • Balance: ^(<(<(<(<(<(<<>>)*>)*>)*>)*>)*>)*$
    • Powers: ^(?!((xx)+x)\1*$)(不存在奇数因子)
    • Long count: ^((.+)0 \2+1 ?)*$
    • Alphabetical: 不会
    • Powers 2: ^(?!(xx|(xxx)+xx?)\1*$)(不存在 3n+1 和 3n+2 的因子)
  • Teukon
    • Subtraction: ^(x+)(x+) - \1 = \2$
    • Typist: ^[^h-quy]+$
    • Addition: ^(.*)(.*)(.*) = \2\1\3$
    • Anyway: ^[^aeiou]?([aeiouy][^aeiou])*[aeiouy]?$(元音辅音相间)
    • Tic-tac-toe: (\w)(\1|..(\1|.\1.|..\1..)..)\1(井字棋)
    • Modulus: ^((x+)(x+))\1*\2 % \1 = \2$|^(x+) % \4x+ = \4$^(?=.*% (x+))(?=\1*(x*)).* \2$
    • Matryoshka: ^((\w*)(\w*) (?=\2\w+\3\b))*\w+$
    • Euclid: (?=\((x+)\1*, \1+\)).* \1$\((x+)\1*, \1+\) = \1$不能保证最大)
    • Latin squares: ^( |(.)(?!(.{5})*.{4}\2)(?=\w* \w*\2)){14}(横竖无重复)
    • Dominoes: ^.?((.).? (\2|(?=.\2)))*\d+$(可以倒转数字对,使相接)
  • Reference