Test and debug regular expressions in real time
The Regex Tester lets you build and debug JavaScript regular expressions against your own text. Every match is highlighted as you type, each capture group — numbered or named — is listed with its position, and a replace preview shows exactly what String.replace would produce.
Regular expressions are compact but cryptic, so the tester also explains your pattern token by token in plain English: which parts are groups, what \b or (?<=…) means, and how each quantifier repeats. A library of ready-made patterns for emails, URLs, phone numbers, IP addresses, dates, colours and postcodes gives you a tested starting point.
Patterns run in a background worker with a time limit, so a runaway expression that would normally freeze the tab is stopped after a second and a half with an explanation. Your text never leaves your browser.
How to use the Regex Tester
- Type a pattern between the slashes, or choose one from Common patterns to load it with sample text.
- Tick the flags you need —
gfor all matches,ito ignore case,mfor line-by-line anchors and so on. - Paste your text into Test string. Matches are highlighted in alternating colours, and empty matches show as a thin marker.
- Read Match details for each match’s index and capture groups.
- Enter a Replace with template such as
$2-$1or$<year>to preview a find-and-replace, then copy the result. - Check Pattern explained to confirm the regex does what you think.
Regex Tester features
Live highlighting
Matches are marked in the text as you type, with HTML safely escaped so tags in your test string are shown, not rendered.
Capture and named groups
Every group is listed per match, including named groups like (?<year>…); with the d flag you also see each group’s start and end index.
Replace preview
Uses JavaScript’s own replacement syntax — $1, $<name>, $&, $`, $' and $$.
Plain-English explanation
Each token — classes, anchors, groups, lookarounds, back-references and quantifiers — is described, indented by nesting level.
Runaway protection
Matching runs in a Web Worker with a 1.5-second limit and a cap of 10,000 matches, and zero-length matches advance safely so nothing loops forever.
Pattern library
Nineteen common patterns, from email and E.164 phone numbers to UK postcodes, Indian PIN codes and UUIDs, each with sample text.
Regex cheat sheet
| Token | Meaning | Example |
|---|---|---|
. | Any character except a line break | c.t → cat, cot |
\d \w \s | Digit, word character, whitespace | \d{3} → 415 |
[abc] [^abc] [a-z] | Character set, negated set, range | [A-Z]\w+ → Pune |
* + ? {n,m} | Repeat 0+, 1+, 0–1, n to m times | a{2,3} → aa, aaa |
*? +? | Lazy versions — as few as possible | <.+?> → one tag |
^ $ \b | Start, end, word boundary | ^\w+$ → a whole line |
( ) (?: ) (?<name> ) | Capturing, non-capturing and named groups | (\d+)-(\d+) |
(?= ) (?! ) (?<= ) (?<! ) | Lookahead and lookbehind | \d+(?=%) → 50 in 50% |
\1 \k<name> | Back-reference to a group | (\w)\1 → ll in hello |
a|b | Alternation (OR) | cat|dog |
Avoiding catastrophic backtracking
JavaScript’s regex engine is a backtracking engine. When a pattern contains nested or overlapping quantifiers, such as (a+)+$ or (\w+\s?)*$, a string that almost matches can force it to try an exponential number of combinations. On a server this is a denial-of-service risk known as ReDoS.
To avoid it, make each part of the pattern match in only one way: replace (.*)* with .*, use specific classes like [^,]* instead of .* between delimiters, and anchor patterns where you can. If this tester times out on your pattern, rewrite it before using it in production.
JavaScript flavour notes
- This tester uses your browser’s JavaScript engine, so results match
RegExpin Chrome, Firefox, Safari and Node.js exactly. - Lookbehind, named groups, the
sflag and Unicode property escapes like\p{L}are supported in all current browsers;\p{…}needs theuorvflag. - PCRE-only features such as possessive quantifiers (
a++), atomic groups and recursion are not available in JavaScript. - Need a simple find-and-replace without regex? Use Find and Replace, or pull addresses straight out of text with the Email Extractor.
Regex Tester FAQ
How do I test a regular expression?
Type the pattern in the regex box, tick the flags you need and paste text into Test string. This regex tester highlights every match instantly and lists the groups for each one, so you can adjust the pattern until it matches exactly what you want.
Why does my regex only find the first match?
Without the g (global) flag, JavaScript stops after the first match. Tick g to find them all.
Why do ^ and $ not match each line?
By default they match only the start and end of the whole text. Tick the m (multiline) flag to make them match at every line break.
Is this the same as PCRE, Python or Java regex?
Most syntax is shared, but there are differences: JavaScript has no possessive quantifiers or atomic groups, and Python uses (?P<name>…) for named groups instead of (?<name>…). Test JavaScript patterns here and check the documentation for other languages.
What happens if my pattern is too slow?
The tester stops it after 1.5 seconds and explains that the pattern is probably backtracking catastrophically, without freezing your browser tab.
Is my test text private?
Yes. Matching runs in your browser in a background worker. Nothing is uploaded or saved.