Test regular expressions with flags, match highlighting, capture group extraction, and replacement preview.
Loading tool
About Regex Tester
Test JavaScript regular expressions against sample text with live match highlighting. Toggle the g, i, m, s, u and y flags, see each match's index range and its numbered and named capture groups, and preview replacements with $1, $<name>, $&, $` and $' substitutions. It uses the browser's own RegExp engine, so results match what your JavaScript code will do.
Common uses
- Build and debug a validation pattern for emails, dates or IDs
- Check what each capture group captures before using it in code
- Preview a find-and-replace that reorders parts of a string
- Test how the multiline and dotAll flags change matching
FAQ
- Which regex flavor does this use?
- JavaScript (ECMAScript) regular expressions, run by your browser's RegExp engine. Syntax that only exists in PCRE or Python, such as possessive quantifiers, is not supported.
- How do named capture groups work in JavaScript?
- Write (?<name>...) to name a group, read it from match.groups.name, and refer to it in a replacement string as $<name>.
- Why is only the first match replaced?
- Without the g flag, String.prototype.replace replaces only the first match. Enable g to replace all matches.
- What does the s (dotAll) flag do?
- Normally . does not match line breaks. With the s flag it matches any character, including newlines.