6

http://regex.alf.nu/ 非标准答案

 3 years ago
source link: https://zxs.io/article/157
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
http://regex.alf.nu/ 非标准答案

网站链接

这是一个练正则表达式的好文章,有几个题目都比较意思,以下是参考答案,如果有得分更高的答案请告诉我,大家交流一下。

  1. Plain strings (207)                             foo
  2. Anchors (206)                                     ick$
  3. Ranges (202)                                     [a-f]{4}
  4. Backrefs (201)                                   (...).*\1
  5. Abba (190)                                          ^((?!(.)(.)\3\2).)+$
  6. A man, a plan (176)                          ^(.)(.).*\2\1$
  7. Prime (286)                                        ^(?!(xx+)\1+$)
  8. Four (199)                                           (.)(.\1){3}
  9. Order (199)                                         ^.{5}[^e]?$
  10. Triples (574)                                       ^(([147]4|40|3[269]|9[05]|[378]1).+|0[369]*|[81][257])*$ 或 00($|3|6|9|12|15)|4.2|.1.+4|55|.17
     关于第10条,可参考 http://www.zhihu.com/question/24824487
  11. Glob (384)                                           (rr|ll|[lbr]o|en|ta|y|cr|eat|up).*\1
  12. Balance (287)                                    ^(<(<(<(<(<(<.*)*>)*>)*>)*>)*>)*$
  13. Powers (80)                                       ^(((x|x{8}|x{128})\3?)\2?)\1?$
  14. Long count (239)                              ((..)00 \2+01 \2+10 \2+11 ?){4}
  15. Long count v2 (239)                         ((..)00 \2+01 \2+10 \2+11 ?){4}
  16. Alphabetical (0)

http://jimliu.net/2014/01/04/regex-golf/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK