正则表达式速查表 — 完整的正则语法参考

正则表达式语法的常用速查参考。按类别浏览,找到所需语法,点击即可复制。涵盖字符、量词、锚点、分组等。

字符

SyntaxDescription
.Any character except newline
\dDigit (0-9)
\wWord character (a-z, A-Z, 0-9, _)
\sWhitespace (space, tab, newline)
\DNon-digit
\WNon-word character
\SNon-whitespace

量词

SyntaxDescription
*Zero or more
+One or more
?Zero or one
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times
*?Zero or more (lazy)
+?One or more (lazy)

锚点

SyntaxDescription
^Start of string/line
$End of string/line
\bWord boundary
\BNon-word boundary

分组

SyntaxDescription
(…)Capturing group
(?:…)Non-capturing group
(?=…)Positive lookahead
(?!…)Negative lookahead
(?<=…)Positive lookbehind
(?<!…)Negative lookbehind
(?<name>…)Named capturing group

字符类

SyntaxDescription
[abc]Match a, b, or c
[^abc]Match anything except a, b, or c
[a-z]Match a through z
[a-zA-Z]Match a-z or A-Z

标志

SyntaxDescription
gGlobal (match all)
iCase-insensitive
mMultiline (^ and $ match lines)
sDotall (. matches newline)
uUnicode support

特殊

SyntaxDescription
|Alternation (OR)
\Escape special character
(…)\1Back-reference to group 1

查看完整英文指南