Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- plain strings (207) foo
- anchors (208) k$
- ranges (202) ^[a-f]*$
- backrefs (201) (...).*\1
- abba (190) ^((?!(.)(.)\3\2).)*$
- a man, a plan (177) ^(.)[^p].*\1$
- prime (286) ^(?!(xx+)\1+$)
- four (199) (.)(.\1){3}
- order (199) ^.{5}[^e]?$
- triples (574) ^(([147]4|40|3[269]|9[05]|[378]1).+|0[369]*|[81][257])*$
- glob (384) (rr|ll|[lbr]o|en|ta|y|cr|eat|up).*\1
- balance (251) ^((<>)*|<(?!>).*>)$ //five false positives.
- powers (59) ^(.|(?!.{48}$)(..)*)$ //three false positives
- longcount (218) 0..1..1.. (..0){3}..1* ..0..1..1..0.. ..11(.{9}1){2}
- longcount2 (218) 0..1..1.. (..0){3}..1* ..0..1..1..0.. ..11(.{9}1){2}
- alphabetical (180) ^(a[er]\w+ ?)*(ass\w+ ?)*(ast+ ?)*(e\w+ ?)*(n\w+ ?)*(r\w+ ?)*(s\w+ ?)*(t\w+ ?)*$ // 4 errors
- These are regex.alf.nu solutions by Bisqwit. Usernames indicated are from Reddit unless otherwise noted.
- Alternatives:
- ranges (202) [a-f]{4} //made of abuse.
- order (199) ^[^o]?.{5}$ //another way of writing the same thing.
- powers (59) ^(x|(xx){1,4}|((((((x{16})\8?)\7?)\6?)\5?)\4?)\3?)$ //zero false positives,
- //with thanks to Hrafnahnef.
- alphabetical (156) ^(a[er]\w+ ?)*(asse[rn]\w+ ?)*(asse[st]\w+ ?)*(ast\w+ ?)*(e[an]\w+ ?)*(e[rts]\w+ ?)*(n\w+ ?)*((?:ra|re[anr])\w+ ?)*(rese\w+ ?)*(rest\w+ ?)*(ret\w+ ?)*(se\w+ ?)*(s[nt]\w+ ?)*(t\w+ ?)*$ // no false positives
- Better solutions by others:
- abba (193) ^(?!.*(.)(.)\2\1) // by Laugarhraun.
- triples (596) 00($|3|6|9|12|15)|4.2|.1.+4|55|.17 // by alexandrosm @ [1]
- glob (397) ai|c$|^p|[bcnrw][bnopr] // by nwellnhof @ [2]
- balance (287) ^(<(<(<(<(<(<.*)*>)*>)*>)*>)*>)*$ // by jensweh.
- balance (288) ^(<(<(<(..)*>)*>)*>)*$ // by romanandreev @ [1]; some false positives
- powers (80) ^(((x|x{8}|x{128})\3?)\2?)\1?$ // by pondscum; no false positives.
- powers (97) ^(?!(.(..)+)\1*$) // by plby @ [1]; doesn't "cheat"
- longcount (253) ^((.+)0 \2+1 ?)*$ // possibly by bbarry @ [3]
- longcount2 (253) ^((.+)0 \2+1 ?)*$ // possibly by bbarry @ [3]
- alphabetical (303) r sn|( t\w+)\1|(tat|r). r|a t| ae|e e // by alexandrosm @ [1]
- Best solutions that work in the spirit of the test without abusing the test-cases:
- (Where different from what is posted above; recursion shortcomings are ignored)
- a man, a plan (176) ^(.)(.).*\2\1$
- triples (523) ^([0369]|[258][0369]*[147]|([258][0369]*[258]|[147])([0369]|[147][0369]*[258])*([258]|[147][0369]*[147]))*$ // by Bisqwit.
- balance (286) ^(<(<(<(<(<(<.*>)*>)*>)*>)*>)*>)*$ // by Overv.
- 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*$ // by Athox.
- glob (323) ^(?:(.+) .+ \1|(.*)\*(.*) .+ \2.+\3|(.*)\*(.*)\*(.*) .+ \4.+\5.+\6|\*(.*)\*(.*)\* .+ .+\7.+\8.+)$ // by Lozzer2
- glob (333) ^(\*?)(\w*)(\*?)(\w*)(\*?)(\w*) .* ((.(?!\1))+|\1)\2((.(?!\3))+|\3)\4((.(?!\5))+|\5)\6$ // by hadrel @ [2]
- [1]: https://gist.github.com/jonathanmorley/8058871
- [2]: https://news.ycombinator.com/item?id=6941231
- [3]: https://gist.github.com/jpsim/8057500
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement