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| Syntax | Meaning | Example |
|---|---|---|
\ | 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|y | Matches 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}) |
\1 | Matches 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 / \D | Matches a digit / a non-digit. Unicode behavior is engine-dependent. | \d+ |
\w / \W | Matches a word character / non-word character. The exact character set depends on the engine. | \w+ |
\s / \S | Matches whitespace / non-whitespace. | \s+ |
\b / \B | Matches a word boundary / a position that is not a word boundary. | \bword\b |
\n, \r, \t | Matches a line feed, carriage return, or tab. | \r?\n |
\xNN | Matches a character by its two-digit hexadecimal code unit. | \x41 matches A. |
\uNNNN | Matches 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}+ |
Go's RE2-based engine intentionally omits lookaround and backreferences. JavaScript requires Unicode mode for many Unicode property escapes. PCRE, .NET, Java, Python, and Ruby also differ in group syntax, flags, and replacement-string rules.
When a pattern processes untrusted or very large input, avoid ambiguous nested quantifiers, set input limits, and test worst-case behavior to reduce the risk of excessive backtracking.