Skip to content

Instantly share code, notes, and snippets.

@Beteat
Forked from JavaCS3/README.md
Created April 29, 2020 03:37
Show Gist options
  • Save Beteat/fbdf50c06331ab24a58279ad242c8568 to your computer and use it in GitHub Desktop.
Save Beteat/fbdf50c06331ab24a58279ad242c8568 to your computer and use it in GitHub Desktop.
正则表达式学习

正则表达式学习

正则表达式是一个可以帮助我们匹配复杂字符串模式的工具

匹配字符(What)

  • .
  • [abcd] [a-zA-Z] [^abcd]
  • \d \s \t \w ...

匹配数量(How)

  • *
  • +
  • ?
  • {n}
  • {n,}
  • {n,m}

子匹配

  • ()

其他

  • a* Greedy 贪婪
  • a*? Lazy
  • |
  • ^ $

例子

93.180.71.3 - - [17/May/2015:08:05:32 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)"
93.180.71.3 - - [17/May/2015:08:05:23 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)"
80.91.33.133 - - [17/May/2015:08:05:24 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.17)"
217.168.17.5 - - [17/May/2015:08:05:34 +0000] "GET /downloads/product_1 HTTP/1.1" 200 490 "-" "Debian APT-HTTP/1.3 (0.8.10.3)"
217.168.17.5 - - [17/May/2015:08:05:09 +0000] "GET /downloads/product_2 HTTP/1.1" 200 490 "-" "Debian APT-HTTP/1.3 (0.8.10.3)"
93.180.71.3 - - [17/May/2015:08:05:57 +0000] "GET /downloads/product_1 HTTP/1.1" 304 0 "-" "Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment