
一个用正则表达式在线闯关的网站:https://alf.nu
正则闯关一共17题:https://alf.nu/RegexGolf#accesstoken=iXkmvEAWnP8kXzcY0m1J
每一题下面会给出两列字符串,左侧是要求匹配的,同时你也不能匹配右边的。
Q1: Warmup – Type a regex in the box.

答案:foo (公共部分)
Q2: Anchors – You are deducted one point per character you use, and ten if you match something you shouldn’t.

答案:k$ (左边全部是以k结尾)
Q3: It never ends – $ not allowed

答案: u\b (以b结尾)
Q4: Ranges – The test vectors were generated by grepping /usr/dict/words. Can you tell?

答案:[a-f]{4,} (4个以上a-f之间的字母组成)
Q5: Backrefs – This doesn’t really work as a tutorial. Not really clear what you’re supposed to do here.

答案:(\w{3})\w?.*?\1 (首尾都是相同的3个字母)
Q6: Abba – Let’s pretend this one is not a rehash of the last one.

答案:^(?!\w*(\w)(\w)\2\1) (匹配不带有’abba’形的单词)
Q7: A man, a plan – You’re allowed to cheat a little. Even in hard mode, words will be no longer than 13 characters.

答案:^(\w)(\w).*?\2\1$ (回文字符串,这里我的不太标准,只匹配了两位)
Q8: Prime

匹配合数:^x?$|^(xx+?)\1+$
答案:^(?!(..+)\1+$) (前瞻枚举不是合数的)
Q9: Four – You can get an extra point by ignoring the name of this level.

答案:(\w)?(\w)(\w)\2(\w)\2(\w)\2 (首先要匹配带有’axbxcxdx’类型的,用(\w)(\w)(\w)\2(\w)\2(\w)\2就行,其次要考虑到’elevener’的类型是’xaxbxcxd’)
Q10: Order – Cheat.

答案:\b[a-m]\w{3,4}[m-z]\b (‘a-m’的字母做开头,中间3-4个字母,最后是’m-z’的字母结尾)
水平有限,暂时只到第十关,后续再更。
- 本文链接: https://anyway521.github.io/post/b7ec83dc.html
- 最后更新:
- 版权声明: 博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议进行许可,转载请注明出处!

