速查表

Expression Condition Example
abc
Letters abc
123
\\d
\\D
Digits
Any Digit
Any Non-digit character
123
.
\\.
Any Character
Period
…\.
[abc]
[^abc]
Only a, b, or c
Not a, b, nor c
[cmf]an
[^b]og
[a-z]
[0-9]
\\w
\\W
Characters a to z
Numbers 0 to 9
Any Alphanumeric character
Any Non-alphanumeric character
[A-C][n-p][a-c]
{m}
{m,}
{m,n}
m Repetitions
m to n Repetitions
waz{3,5}up
*
+
Zero or more repetitions
One or more repetitions
aa+b*c+
?
\\?
Optional character \d+ files? found\?
\\s
\\S
Any Whitespace
Any Non-whitespace character
\d\.\s+abc
^$
Starts and ends ^Mission: successful$
()
Capture Group ^(file.+)\.pdf$
(a(bc)``)
Capture Sub-group (\w+ (\d+))
(.*)
Capture all (\d+)x(\d+)
(abc|def)
Matches abc or def I love (cats|dogs)

参考

  1. regexone.com - Learn Regular Expressions with simple, interactive exercises. 👍
  2. https://regexr.com 👍
Regex 101 Debuggex Useful Regex Patterns
Learn Regex

https://regexr.com/
https://www.codejiaonang.com/#/course/regex_chapter1/2/4