Skip to content

Instantly share code, notes, and snippets.

@JavaCS3
Last active June 28, 2023 01:40
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JavaCS3/e36e494e78a02049950bfa7c7ebeb929 to your computer and use it in GitHub Desktop.
Save JavaCS3/e36e494e78a02049950bfa7c7ebeb929 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