Regex Tester
Real-time matching with per-group highlighting and capture-group breakdown; empty matches are skipped automatically so complex patterns are safe to test.
>_ USAGE GUIDE
Type the pattern on top, toggle the flags g/i/m/s/u/y as six visual switches (the effective combination is shown live), paste your test text below, and matches highlight in real time — edit a single character and the highlights update instantly. Every capture group is broken out and listed separately, so extraction patterns (pulling fields out of logs, for example) are far easier to debug. Zero-length matches are skipped automatically.
The Replace box supports the full reference syntax — $1, $2, $&, ` $ `, $' and named groups $<name> — with a live replace preview right below. Without the g` flag the tool clearly states "only the first match is replaced"; a replacement referencing a non-existent named group turns the notice yellow without interrupting the match view. The template library ships 20 ready-made patterns (email, URL, IPv4, phone, date, thousands separator, CJK characters, HEX color, UUID, log level, and more) — one click fills in the pattern, flags and test text together.
- Enter the pattern: write your expression and light up the flags you need
- Paste test text: matches are highlighted as you type, with no run button
- Try a replacement: type
$1-style references and read the live preview - Start from a template: click any of the 20 library entries to prefill pattern and sample text
All matching executes locally in your browser, so your test text never leaves the device and complex expressions are safe to experiment with.
>_ FAQ
Q1 · My regex matches nothing — how do I debug it?
Check in this order: ① extra escaping on groups (a literal ( needs \(); ② missing g flag so only the first match shows — flip the g switch on the flags panel; ③ newlines — . does not match line breaks by default, use [\s\S] or enable s; ④ invisible characters in the target text (full-width spaces, BOM). With live highlighting here, paste the pattern and text and tweak segment by segment — the failing part becomes visible immediately.
Q2 · What do $1 and $& mean in a replacement?
$1~$9 reference the nth capture group, $& the whole match, ` $ ` the text before the match, $' the text after, and $<name> a named group. For example, matching (\d{4})-(\d{2})-(\d{2}) and replacing with $1/$2/$3 turns 2026-03-15 into 2026/03/15`. Type it into the replace box here and the preview shows the result instantly.
Q3 · Why did my replacement only change the first occurrence?
The g (global) flag is off. With g on, every match is replaced; without it only the first — and the tool states this explicitly. The y (sticky) flag is even more specialized, anchoring each match at lastIndex; it is rarely what you want while debugging.
Q4 · Are there ready-made common regexes?
Yes — the template library at the bottom of the page ships 20 entries: email, URL, IPv4, phone, date, date-time, thousands-separated numbers, CJK characters, HEX color, MD5/SHA-256 hashes, UUID, integers and decimals, HTML tags, key=value, log-level lines, CN-ID length, IP:port, double-quoted strings, and repeated whitespace. One click fills pattern and test text; tweak and go. All templates avoid nested quantifiers, so none can trigger catastrophic backtracking.
Q5 · Does regex syntax differ between languages?
The core syntax (character classes, quantifiers, grouping) is universal, but details differ: JavaScript has caught up on lookbehind and other advanced features in recent years, Python's re is close to PCRE, and Go's RE2 deliberately does no backtracking (hence no catastrophic backtracking either). This tool uses the JavaScript engine, so results match what your JS/TS code will do; cross-check syntax details when targeting other languages.