发现一个正则闯关的网站,可以玩一下

2019-08-26 14:32:22 +08:00
 byron
https://alf.nu/RegexGolf

自己玩玩看,可以复习(锻炼)一下正则的很多语法及用法。
13147 次点击
所在节点    程序员
94 条回复
a494836960
2019-08-27 10:55:44 +08:00
感觉更像找规则,,,写正则并不难
byron
2019-08-27 11:07:38 +08:00
@AddictX 哈哈,果真有 Cheat。
byron
2019-08-27 11:08:52 +08:00
@Biwood 这题有 Cheat,左右长度不一样^_^
daguaochengtang
2019-08-27 11:11:16 +08:00
我第 3 提就不会了,考零宽断言或者单词边界
qq316107934
2019-08-27 11:28:15 +08:00
做到怀疑人生,regex 能匹配回文串吗?
qq316107934
2019-08-27 11:47:04 +08:00
Four 这道题,(.).\1.\1.\1 12 个字符,还能缩到 11 个吗,表示怀疑
jsq2627
2019-08-27 11:56:11 +08:00
@qq316107934 #66 (.)(.\1){3}
byron
2019-08-27 12:36:02 +08:00
@nikolausliu 单词边界就是语法,查一下就好了。
gerorim
2019-08-27 12:50:08 +08:00
@honjow #32

and none of these …
✔xxxx (no match)
✔xxxxxx (no match)
✔xxxxxxxx (no match)
✔xxxxxxxxx (no match)
✔xxxxxxxxxx (no match)
✔xxxxxxxxxxxx (no match)
✔xxxxxxxxxxxxxx (no match)
✔xxxxxxxxxxxxxxx (no match)
✔xxxxxxxxxxxxxxxx (no match)
✔xx …(18)… xx (no match)
✔xx …(20)… xx (no match)
✔xx …(21)… xx (no match)
✔xx …(22)… xx (no match)
✔xx …(24)… xx (no match)
✔xx …(25)… xx (no match)
✔xx …(26)… xx (no match)
✔xx …(27)… xx (no match)
✔xx …(28)… xx (no match)
✔xx …(30)… xx (no match)
✔xx …(32)… xx (no match)

^(?!(xx+)\1+$)

https://sm.ms/image/E1Ppn3IyQJBC9HZ

注意上面的粉红色光标,断言后面的 xx...xx 串不能被 2 个以上的 xx+ 组成的重复串完全匹配,其中 xx+ 视作因数(数值>1 ),而反引用使得它不能被本身匹配。
联系质数的数学定义:大于 1 的自然数中,除了 1 和它本身以外不再有其他因数的自然数。

从上面的粉红光标处出发,再加两个 xx (确保自然数大于 1 )即为答案

Match all of these …
✔xx
✔xxx
✔xxxxx
✔xxxxxxx
✔xxxxxxxxxxx
✔xxxxxxxxxxxxx
✔xxxxxxxxxxxxxxxxx
✔xxx …(18)… xx
✔xxx …(22)… xx
✔xxx …(28)… xx
✔xxx …(30)… xx
✔xxx …(36)… xx
✔xxx …(40)… xx
✔xxx …(42)… xx
✔xxx …(46)… xx
✔xxx …(52)… xx
✔xxx …(58)… xx
✔xxx …(60)… xx
✔xxx …(66)… xx
✔xxx …(70)… xx

^(?!(xx+)\1+$)xx
gerorim
2019-08-27 12:53:27 +08:00
bigtwo
2019-08-27 12:57:45 +08:00
@ptrees 这么牛 b 吗,json 也用正则取,对于我来说不敢想更不敢做,json 类都是套用第三方工具取
aaronchou0
2019-08-27 13:38:56 +08:00
这个跟正则关系不大吧,就是找规律
ahsjs
2019-08-27 13:57:04 +08:00
第七题 ^(.)(.).*\2\1$ 这个 14 个字符 13 个字符怎么破
byron
2019-08-27 14:31:12 +08:00
@ahsjs You're allowed to cheat a little.

左边没 p
silentsee
2019-08-27 14:40:21 +08:00
这个把正则里的元字符,范围,非,分组,负向引用,零宽断言,都练习了一遍,挺好的
silentsee
2019-08-27 14:41:15 +08:00
@ahsjs ^(?!(.)+\1)|ef
HGladIator
2019-08-27 14:51:48 +08:00
GitHub 一堆这个网站的答案,
rocketman13
2019-08-27 15:26:08 +08:00
@byron 第五题的 9 怎么写呀
5200
2019-08-27 15:32:27 +08:00
@ahsjs #73 ^(.)[^p].*\1$ 不会被打吧

@rocketman13 #78 (...).*\1
cuiqiangtj
2019-08-27 15:38:31 +08:00
Long count (15 题)这题最简单,直接吧左边的贴上去就过关---哈哈

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://ex.noerr.eu.org/t/595193

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX