简单的正则表达式语法总结

General




Choice
Sequence | Sequence | ...

 


Sequence
Factor Quantifier ...

 



Factor

  • Groups
  • Classes
  • Characters & Escapes

Quantifier


  • * 0 or more times
  • ? 0 or 1 times
  • + 1 or more times
  • {N} exactly N times
  • {N,} N or more times
  • {N,M} N through M times


 


Groups




Capturing Group
(RegExp)


Non-capturing Group

(?:RegExp)


Non-greedy Matching

(RegExp?)


Backreference

\1 ... \N

 


Classes




Basic
[12345], [abcde]
Ranges
[1-5], [a-e]
Complements "Not In"
[^6-9], [^f-z]
Characters Needing Escape
- / [ \ ] ^

 


Chars




Characters
Any Unicode character except:/\ [] () {} ? + * |
special/ctrl- char

 


Special Characters

  • ^ Start of Line
  • $ End of Line
  • . Any character except end of line

Escapes


\d Digit \D Non-digit
\s Whitespace \S Non-whitespace
\w "Word" \W Non-"Word"
\n New Line \f Formfeed
\t Tab \r Carriage Return
\uNNNN Unicode where N is hex

HiFI Regex Tester的测试工具非常不错,AdminBy翻译的中文版也非常好用,保留了HiFI Regex Tester功能和风格,并且在国内的加载速度比HiFI Regex Tester快多了,适合正则表达式学习和测试。

关键字:正则表达式

本文链接:树叶的BLOG >> 简单的正则表达式语法总结

本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。

上一篇 : CodeGuard-非常不错的网站自动备份服务 下一篇 : Evernote 去广告补丁