Highlighted Matches
Capture Groups
How to use the Regex Tester
- Enter your regular expression pattern in the Pattern field.
- Enable flags as needed:
gfinds all matches,iignores case,mmakes^and$match line boundaries,smakes.match newlines. - Paste your test string, matches are highlighted in real time and capture groups are listed below.
JavaScript regex syntax quick reference
| Token | Meaning |
|---|---|
. | Any character except newline |
\d / \D | Digit / non-digit |
\w / \W | Word character [a-zA-Z0-9_] / non-word |
\s / \S | Whitespace / non-whitespace |
^ / $ | Start / end of string (or line with m flag) |
\b | Word boundary |
+ | One or more (greedy) |
* | Zero or more (greedy) |
? | Zero or one (optional) |
{n,m} | Between n and m repetitions |
[abc] | Character class (any of a, b, c) |
[^abc] | Negated class (anything except a, b, c) |
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
a|b | Alternation (a or b) |
Common regex patterns
- Email address:
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} - URL:
https?://[^\s/$.?#][^\s]* - IP address:
\b(?:\d{1,3}\.){3}\d{1,3}\b - Date (YYYY-MM-DD):
\d{4}-\d{2}-\d{2} - Hex color:
#(?:[0-9a-fA-F]{3}){1,2}\b
Greedy vs lazy matching
By default, quantifiers (+, *, {n,m}) are greedy: they match as much as possible. Add ? after the quantifier to make it lazy (match as little as possible): +?, *?, {n,m}?. Example: <.+?> matches individual HTML tags instead of everything from the first < to the last >.
Engine differences: JavaScript vs PCRE vs RE2
Regex syntax looks similar across engines but behaves differently in key areas. A pattern that works in your browser may fail in PHP, Python, or Go:
| Feature | JavaScript (this tool) | PCRE (PHP, Python, Perl) | RE2 (Go, Rust) |
|---|---|---|---|
Lookbehind (?<=...) | Fixed-length (ES2018+) | Variable-length | Fixed-length only |
Backreferences | Yes | Yes | No |
Atomic groups (?>...) | No | Yes | No |
Unicode classes \p{L} | Yes (with u flag) | Yes | Yes (default) |
\d matches Unicode digits | No (ASCII only without u) | Yes (default in PCRE2) | No (ASCII only) |
5 common pitfalls
- Catastrophic backtracking: A pattern like
(a+)+bon a long string of 'a' with no 'b' triggers exponential backtracking and can freeze your app. Avoid nested quantifiers on overlapping patterns. Always test with long, non-matching input. - \d and Unicode digits: Without the
uflag,\donly matches ASCII 0-9, not Arabic-Indic (٠-٩) or other Unicode digit forms. Adduand use\p{N}if you need all Unicode digits. - ^ and $ without the m flag: By default,
^and$match the start and end of the whole string. For per-line anchors on multi-line input, add themflag. - Greedy match eating the whole string:
<.+>on<b>text</b>matches from the first<to the last>. Use lazy<.+?>to match one tag at a time. - Unescaped dots in domain patterns: The dot matches any character.
example.comalso matchesexampleXcom. Escape literal dots:example\.com.