Regex Tester Online — Test, Highlight and Replace Safely
Test JavaScript regular expressions with live match highlighting, capture groups, flags and replacement preview. Runs locally in your browser.
Regex Tester
How to Use This Tool
- 01 Type or paste your pattern into the pattern field without the surrounding slashes. For example, enter \d{3}-\d{4} rather than /\d{3}-\d{4}/.
- 02 Paste the text you want to search into the test text area. Real samples work best: include lines that should match and a few that should not.
- 03 Toggle the flags you need. Use g to find every match, i to ignore letter case, m so ^ and $ work per line, s so the dot matches line breaks, and u for full Unicode handling.
- 04 Review the highlighted preview and the match list. Each entry shows the matched text, its start position and every capture group, including named groups.
- 05 Switch to replace mode to preview a rewrite with references like $1, $& or $<name>. Copy the output or the pattern once it behaves the way you expect.
How It Works
Practical Examples
Extract email addresses with named groups
Pattern: (?<user>[A-Za-z0-9._%+-]+)@(?<domain>[A-Za-z0-9.-]+\.[A-Za-z]{2,}) Flags: g Text: Contact [email protected] or [email protected]
2 matches: [email protected] (user=ada, domain=example.com) and [email protected] (user=li.team, domain=sample.org)
Named groups label the parts of each match, so the result list is easy to read and the same names can be used in the replacement string.
Reformat a date with a replacement
Pattern: (\d{4})-(\d{2})-(\d{2}) Replacement: $3/$2/$1 Text: Released on 2025-03-14
Released on 14/03/2025
Each pair of parentheses becomes a numbered group. The replacement reorders the groups, turning an ISO date into a day-first date without touching the surrounding text.
Match line starts with the multiline flag
Pattern: ^ERROR.*$ Flags: g, m Text: INFO ok
ERROR disk full
WARN slow
ERROR timeout
2 matches: "ERROR disk full" and "ERROR timeout"
Without the m flag, ^ and $ only match at the start and end of the whole text. With it, they match at every line, which is what you want when scanning logs.
Tips & Best Practices
- Start with a small sample and add edge cases one at a time, so you can see exactly which change broke or fixed a match.
- Prefer specific classes such as \d or [A-Za-z] over a bare dot, and avoid nested quantifiers like (a+)+ that can cause catastrophic backtracking.
- Escape special characters such as . ? + * ( ) [ ] { } | \ ^ $ when you mean them literally.
- Use the u flag when your text contains emoji or non-Latin letters, and use named groups to keep long patterns readable.
- A pattern that works on a sample is not proof of correctness for validation. Test hostile and empty inputs, and validate on the server as well.
Frequently Asked Questions
Which regex flavor does this tester use?
It uses the JavaScript (ECMAScript) regular expression engine of your browser. Syntax and behavior match JavaScript and Node.js, but may differ from PCRE, Python, Java or .NET, so double-check patterns you will run in other languages.
Is my text sent to a server?
No. The pattern and the test text are processed locally in your browser. Nothing is uploaded, so you can test with logs or sample data, although you should still avoid pasting secrets into any page you do not control.
What do the g, i, m, s and u flags do?
g finds all matches instead of the first, i ignores letter case, m makes ^ and $ match at each line, s lets the dot match newlines, and u enables full Unicode matching including code points beyond the basic plane.
Why does my pattern stop with a time or match limit warning?
To protect the page from catastrophic backtracking and huge outputs, the tester limits input size, the number of matches and the running time. Simplify nested quantifiers or narrow the pattern, and the warning should disappear.
How do I use capture groups in the replacement?
Use $1, $2 and so on for numbered groups, $<name> for named groups, $& for the whole match and $$ for a literal dollar sign. These follow the behavior of JavaScript String.replace.
Why does my pattern match only once?
Without the g flag, a JavaScript regular expression returns only the first match. Enable the g flag to highlight and list every match in the text.
Related Tools
Base64 Encoder
Encode and decode UTF-8 text, JWT-ready URL-safe Base64, and files to Data URIs instantly in your browser with live validation and zero server uploads.
CSV ↔ JSON
Convert CSV to JSON and JSON to CSV bidirectionally in your browser with full RFC-4180 quote handling, custom delimiters, header toggles, and instant download.
JSON Formatter
Beautify, validate, sort keys, and minify JSON payloads instantly in your browser with line-by-line error diagnostics and one-click download.
JWT Decoder
Decode JWT headers and payloads; inspect signature segments and expiry dates instantly. Review claims locally in your browser with clear warnings.