使用方法
- 在搜索框中输入关键字,如"lookahead"、"quantifier"或 "\d"以过滤条目。
- 点击类别徽章以将结果范围缩小到锚点、组、量词、类或前看。
- 点击任何卡片以将其语法复制到剪贴板。
- 使用底部的复制链接按钮分享您的过滤视图。
示例
- 搜索"lookahead"将列表范围缩小到 (?=...) 和 (?!...) 条目,带有描述和示例。
- 点击量词徽章显示 +、*、?、{n,m} 等条目 — 每张卡片显示语法、描述和短示例字符串。
正则表达式元字符·标志·类的交互式参考
38 entries
.Any single character except newline
a.c → 'abc'
\dDigit (0-9)
\d+ → '123'
\DNon-digit
\D+ → 'abc'
\wWord char [A-Za-z0-9_]
\w+ → 'foo_1'
\WNon-word char
\W → '!'
\sWhitespace (space, tab, newline)
a\sb → 'a b'
\SNon-whitespace
\S+ → 'foo'
\bWord boundary
\bcat\b → 'cat'
\BNon-word boundary
\Bcat → 'concat'
*0 or more (greedy)
a* → '', 'aaa'
+1 or more (greedy)
a+ → 'aaa'
?0 or 1 (optional)
colou?r → 'color', 'colour'
{n}Exactly n times
\d{4} → '2025'
{n,}n or more times
\d{2,} → '12', '123'
{n,m}Between n and m times
\d{2,4} → '12', '1234'
*?0 or more (lazy)
<.*?> → '<a>', '<b>'
+?1 or more (lazy)
.+? → minimal match
[abc]Any one of a, b, c
[aeiou] → vowels
[^abc]None of a, b, c
[^0-9] → non-digit
[a-z]Range a to z
[A-Za-z] → letters
[\d\s]Combined classes
[\d\.] → digit or dot
^Start of string (or line with /m)
^foo → starts with foo
$End of string (or line with /m)
bar$ → ends with bar
(abc)Capturing group
(\d+)-(\w+) → captures both
(?:abc)Non-capturing group
(?:foo|bar)+
(?<name>abc)Named capture group
(?<year>\d{4})
a|bAlternation (or)
cat|dog → 'cat' or 'dog'
\1Backreference to group 1
(\w)\1 → 'oo' in 'book'
(?=abc)Positive lookahead
\d(?=px) → '12' in '12px'
(?!abc)Negative lookahead
\d(?!px) → digit not followed by px
(?<=abc)Positive lookbehind
(?<=\$)\d+ → '100' in '$100'
(?<!abc)Negative lookbehind
(?<!\$)\d+ → digit not after $
gGlobal — all matches
/foo/g
iCase-insensitive
/FOO/i → matches 'foo'
mMultiline — ^/$ per line
/^line/m
sDotall — . matches newline
/a.b/s
uUnicode mode
/\u{1F600}/u
ySticky — match from lastIndex
/foo/y
生产环境使用前请验证输出。无担保 — 参见 条款.