Regex syntax cheat sheet
A regular expression describes a text pattern. The engine scans the test string from left to right and reports every place where the pattern fits. These are the building blocks you will use most often:
| Token | Meaning | Example |
|---|---|---|
. | Any single character except a line break | a.c → abc, a-c |
\d / \D | A digit 0–9 / any non-digit | \d{3} → 123 |
\w / \W | A letter, digit or underscore (ASCII only) / anything else | \w+ → user_01 |
\s | Whitespace: space, tab, line break and other Unicode spaces | \s+ |
\b | Word boundary (zero-width) | \bcat\b does not match “concat” |
[abc] / [^abc] | One of a, b, c / any character except them | [0-9a-f] → a hex digit |
* / + / ? | 0 or more / 1 or more / 0 or 1 | colou?r → color, colour |
{n,m} | Between n and m times | \d{2,4} |
*? / +? | Lazy versions: match as little as possible | <.+?> → one HTML tag |
^ / $ | Start / end of input (of each line with the m flag) | ^# |
( ) / (?: ) | Capturing group / non-capturing group | (\d+)px → $1 = 12 |
(?<name> ) | Named capturing group | (?<year>\d{4}) |
(?= ) / (?<= ) | Lookahead / lookbehind (zero-width) | \d+(?=%) → 50 in “50%” |
a|b | a or b | jpg|png |
Flags
| Flag | Meaning |
|---|---|
g | Global: find all matches (without it, only the first one) |
i | Case-insensitive |
m | Multiline: ^ and $ match at the start and end of every line |
s | dotAll: . also matches line breaks |
u | Unicode mode: treats emoji as one character and enables \p{…} property escapes |
y | Sticky: match only at the current position |
d | Generate start/end indices for each capture group |
Using the replacement field
The replacement is applied with JavaScript's String.prototype.replace. Use $1, $2… for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. For example, the ISO date preset with the replacement $<month>/$<day>/$<year> turns 2026-10-04 into 10/04/2026. Without the g flag only the first match is replaced.
Frequently asked questions
Will my regex behave the same in Python, PHP or Java?
The core syntax is shared, but details differ between engines. This tester uses your browser's JavaScript engine. For example, Python writes named groups as (?P<name>…), and support for lookbehind or Unicode properties varies by language and version. Test in your target language before shipping.
Why did the page freeze when I typed a pattern?
Nested quantifiers such as (a+)+$ can cause catastrophic backtracking, where the work grows exponentially with the input length (ReDoS). Reload the page and rewrite the pattern so that repetitions cannot overlap.
What is the perfect regex for email addresses?
A regex that fully follows RFC 5322 is extremely long and impractical. Use a simple pattern like the preset to catch typos, then confirm the address really exists by sending a verification email.
Is my test data uploaded?
No. Matching and replacing happen entirely in your browser, so it is safe to paste log files or other internal text.