EasyDebug.NET

Regex Cheat Sheet

Quick reference for regular expression syntax: character classes, quantifiers, anchors, groups, lookarounds, flags, and common examples. Search, filter, and copy in one click.

49 entries

.
任意字符Character Classes

Matches any single character except newline.

\d
数字Character Classes

Matches a digit, equivalent to [0-9].

\D
非数字Character Classes

Matches a non-digit character, equivalent to [^0-9].

\w
单词字符Character Classes

Matches a letter, digit, or underscore, equivalent to [A-Za-z0-9_].

\W
非单词字符Character Classes

Matches a character that is not a letter, digit, or underscore.

\s
空白字符Character Classes

Matches a whitespace character: space, tab, newline, etc.

\S
非空白字符Character Classes

Matches a non-whitespace character.

[abc]
字符集合Character Classes

Matches any one character listed inside the brackets.

[^abc]
否定字符集Character Classes

Matches any character not listed inside the brackets.

[a-z]
字符范围Character Classes

Matches any character in the given range, e.g. [a-z] for lowercase letters.

[\u4e00-\u9fa5]
汉字范围Character Classes

Matches a Chinese character (CJK Unified Ideographs basic block).

*
0 次或多次Quantifiers

Repeats the preceding element 0 or more times, same as {0,}.

+
1 次或多次Quantifiers

Repeats the preceding element 1 or more times, same as {1,}.

?
0 次或 1 次Quantifiers

Makes the preceding element optional (0 or 1 time), same as {0,1}.

{n}
精确 n 次Quantifiers

Repeats the preceding element exactly n times, e.g. \d{4} for 4 digits.

{n,}
至少 n 次Quantifiers

Repeats the preceding element at least n times.

{n,m}
n 到 m 次Quantifiers

Repeats the preceding element between n and m times (inclusive).

*? +? ??
懒惰匹配Quantifiers

Appending ? to a quantifier makes it lazy (non-greedy), matching as little as possible.

^
行首锚点Anchors

Matches the start of the string; with the m flag, the start of each line.

$
行尾锚点Anchors

Matches the end of the string; with the m flag, the end of each line.

\b
单词边界Anchors

Matches a word boundary position without consuming characters.

\B
非单词边界Anchors

Matches a position that is not a word boundary.

(...)
捕获分组Groups & References

Groups the content and captures the match for backreference.

(?:...)
非捕获分组Groups & References

Groups without capturing; does not consume a group number.

(?<name>...)
命名分组Groups & References

Names the capture group so it can be referenced by name.

\1
反向引用Groups & References

Backreferences the content matched by group 1, e.g. (ab)\1 matches abab.

a|b
或运算Groups & References

Matches either the left or right side of the pipe.

(?=...)
正向先行断言Lookarounds

Positive lookahead: succeeds if followed by the pattern, without consuming it.

(?!...)
负向先行断言Lookarounds

Negative lookahead: succeeds if NOT followed by the pattern.

(?<=...)
正向后行断言Lookarounds

Positive lookbehind: succeeds if preceded by the pattern.

(?<!...)
负向后行断言Lookarounds

Negative lookbehind: succeeds if NOT preceded by the pattern.

g
全局标志Flags

Global flag: finds all matches instead of the first.

i
忽略大小写Flags

Case-insensitive flag: ignores letter case.

m
多行模式Flags

Multiline flag: makes ^ and $ match at each line boundary.

s
单行模式Flags

Dotall flag: lets . match newline characters too.

u
Unicode 模式Flags

Unicode flag: treats patterns as Unicode code points, handling emoji correctly.

y
粘性匹配Flags

Sticky flag: matches only at the lastIndex position.

\.
转义点号Escapes

Matches a literal dot instead of any character.

\n \t \r
控制字符Escapes

Match newline, tab, and carriage return respectively.

\u{1F600}
Unicode 转义Escapes

Matches a Unicode character by code point; requires the u flag, e.g. emoji.

^[1-9]\d*$
正整数Common Examples

Matches a positive integer not starting with 0.

^1[3-9]\d{9}$
手机号(中国大陆)Common Examples

Matches an 11-digit Chinese mainland mobile number.

^[\w.-]+@[\w-]+(\.[\w-]+)+$
邮箱Common Examples

Matches a commonly formatted email address.

^https?://[^\s]+$
URLCommon Examples

Matches an http or https URL.

^(\d{1,3}\.){3}\d{1,3}$
IPv4 地址Common Examples

Matches a dotted-decimal IPv4 address (no 0-255 range check).

^\d{4}-\d{2}-\d{2}$
日期Common Examples

Matches a date in YYYY-MM-DD format.

^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$
强密码Common Examples

At least 8 characters containing both letters and digits.

<[^>]+>
HTML 标签Common Examples

Matches an angle-bracket HTML tag.

[\u4e00-\u9fa5]+
提取汉字Common Examples

Extracts consecutive Chinese characters from text.