Regex Syntax Reference

Find a regex construct and see what it means. Check engine-specific behavior before using advanced syntax in your pattern.

Runs locally in your browser
SyntaxMeaningExample
\Escapes a metacharacter or starts a special sequence.\. matches a literal dot.
^Matches the start of the input, or the start of a line in multiline mode.^Error
$Matches the end of the input, or the end of a line in multiline mode.done$
.Matches one character; line breaks are excluded unless dot-all mode is enabled.a.c
*Repeats the previous token zero or more times.ab*c
+Repeats the previous token one or more times.ab+c
?Makes the previous token optional.colou?r
{n}Repeats the previous token exactly n times.\d{4}
{n,}Repeats the previous token at least n times.\w{3,}
{n,m}Repeats the previous token from n through m times.[A-F0-9]{2,8}
*?, +?, ??Uses lazy repetition and consumes as little input as possible.<.*?>
[abc]Matches one character from the set.gr[ae]y
[^abc]Matches one character that is not in the set.[^0-9]
[a-z]Matches one character in the specified range.[A-Za-z]
x|yMatches the expression on the left or the expression on the right.cat|dog
(pattern)Groups a subexpression and captures its match.(ab)+
(?:pattern)Groups a subexpression without creating a capture.(?:https?)://
(?<name>pattern)Creates a named capture group where the engine supports it.(?<year>\d{4})
\1Matches the same text captured by the first group.\b(\w+)\s+\1\b
(?=pattern)Positive lookahead: requires a following match without consuming it.\d+(?=px)
(?!pattern)Negative lookahead: requires that the following text does not match.foo(?!bar)
(?<=pattern)Positive lookbehind: requires a preceding match without consuming it.(?<=\$)\d+
(?<!pattern)Negative lookbehind: requires that the preceding text does not match.(?<!-)\b\d+
\d / \DMatches a digit / a non-digit. Unicode behavior is engine-dependent.\d+
\w / \WMatches a word character / non-word character. The exact character set depends on the engine.\w+
\s / \SMatches whitespace / non-whitespace.\s+
\b / \BMatches a word boundary / a position that is not a word boundary.\bword\b
\n, \r, \tMatches a line feed, carriage return, or tab.\r?\n
\xNNMatches a character by its two-digit hexadecimal code unit.\x41 matches A.
\uNNNNMatches a character by a four-digit Unicode code unit in engines that support this notation.\u00A9 matches ©.
\p{Letter}Matches a Unicode property when Unicode property escapes are supported and enabled.\p{Letter}+
Recent tools: