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
.Matches any single character except newline.
\dMatches a digit, equivalent to [0-9].
\DMatches a non-digit character, equivalent to [^0-9].
\wMatches a letter, digit, or underscore, equivalent to [A-Za-z0-9_].
\WMatches a character that is not a letter, digit, or underscore.
\sMatches a whitespace character: space, tab, newline, etc.
\SMatches a non-whitespace character.
[abc]Matches any one character listed inside the brackets.
[^abc]Matches any character not listed inside the brackets.
[a-z]Matches any character in the given range, e.g. [a-z] for lowercase letters.
[\u4e00-\u9fa5]Matches a Chinese character (CJK Unified Ideographs basic block).
*Repeats the preceding element 0 or more times, same as {0,}.
+Repeats the preceding element 1 or more times, same as {1,}.
?Makes the preceding element optional (0 or 1 time), same as {0,1}.
{n}Repeats the preceding element exactly n times, e.g. \d{4} for 4 digits.
{n,}Repeats the preceding element at least n times.
{n,m}Repeats the preceding element between n and m times (inclusive).
*? +? ??Appending ? to a quantifier makes it lazy (non-greedy), matching as little as possible.
^Matches the start of the string; with the m flag, the start of each line.
$Matches the end of the string; with the m flag, the end of each line.
\bMatches a word boundary position without consuming characters.
\BMatches a position that is not a word boundary.
(...)Groups the content and captures the match for backreference.
(?:...)Groups without capturing; does not consume a group number.
(?<name>...)Names the capture group so it can be referenced by name.
\1Backreferences the content matched by group 1, e.g. (ab)\1 matches abab.
a|bMatches either the left or right side of the pipe.
(?=...)Positive lookahead: succeeds if followed by the pattern, without consuming it.
(?!...)Negative lookahead: succeeds if NOT followed by the pattern.
(?<=...)Positive lookbehind: succeeds if preceded by the pattern.
(?<!...)Negative lookbehind: succeeds if NOT preceded by the pattern.
gGlobal flag: finds all matches instead of the first.
iCase-insensitive flag: ignores letter case.
mMultiline flag: makes ^ and $ match at each line boundary.
sDotall flag: lets . match newline characters too.
uUnicode flag: treats patterns as Unicode code points, handling emoji correctly.
ySticky flag: matches only at the lastIndex position.
\.Matches a literal dot instead of any character.
\n \t \rMatch newline, tab, and carriage return respectively.
\u{1F600}Matches a Unicode character by code point; requires the u flag, e.g. emoji.
^[1-9]\d*$Matches a positive integer not starting with 0.
^1[3-9]\d{9}$Matches an 11-digit Chinese mainland mobile number.
^[\w.-]+@[\w-]+(\.[\w-]+)+$Matches a commonly formatted email address.
^https?://[^\s]+$Matches an http or https URL.
^(\d{1,3}\.){3}\d{1,3}$Matches a dotted-decimal IPv4 address (no 0-255 range check).
^\d{4}-\d{2}-\d{2}$Matches a date in YYYY-MM-DD format.
^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$At least 8 characters containing both letters and digits.
<[^>]+>Matches an angle-bracket HTML tag.
[\u4e00-\u9fa5]+Extracts consecutive Chinese characters from text.