JavaScript Regex Tester
Type a regular expression and test string to see every match, captured group, and replacement result update in real time. Everything runs client-side using JavaScript's native RegExp engine - nothing is sent to a server.
Try These Examples
-
\\b(\\w+)@(\\w+)\\.(\\w+)\\b— Match email addresses and extract local part, domain, and TLD -
https?://[^\\s/$.?#].[^\\s]*— Match HTTP and HTTPS URLs in text -
(\\d{4})-(\\d{2})-(\\d{2})— Match ISO dates and reformat to MM/DD/YYYY
How It Works
This tool uses JavaScript's built-in RegExp constructor to create a regular expression from your pattern and selected flags. Here is a quick overview of the key concepts:
The RegExp Constructor
When you type a pattern, the tool calls new RegExp(pattern, flags). This is the dynamic way to create regular expressions in JavaScript - unlike literal syntax (/pattern/flags), the constructor accepts strings, which means you do not need to escape forward slashes but you do need to double-escape backslashes (e.g., type \\d+ to match digits).
Finding Matches: exec() vs match()
String.prototype.match() with the g flag returns an array of all matched substrings but does not include capture groups. To get full details - including group values and indices - this tool uses RegExp.prototype.exec() in a loop, which returns one match at a time with its captured groups.
Flags Explained
- g (global) - find every match, not just the first.
- i (ignoreCase) - make the pattern case-insensitive.
- m (multiline) - let
^and$match at line boundaries, not just the start and end of the string. - s (dotAll) - let
.match newline characters as well. - u (unicode) - treat the pattern and input as Unicode; enables correct handling of surrogate pairs and Unicode property escapes.
Replacement Strings
The replacement preview uses String.prototype.replace(). You can reference captured groups with $1, $2, etc., use $& for the full match, $` for the text before the match, and $' for the text after.
Frequently Asked Questions
What is the difference between the g and m flags in JavaScript regex?
The g (global) flag finds all matches in the string instead of stopping after the first one. The m (multiline) flag changes the behaviour of ^ and $ so they match the start and end of each line, not just the start and end of the entire string. You can use both flags together.
Why does my regex work in other languages but not in JavaScript?
JavaScript's RegExp engine does not support lookbehind assertions in older browsers, possessive quantifiers, or atomic groups. Some features like the s (dotAll) flag and named capture groups were only added in ES2018. Always check browser compatibility if you need to support older environments.
Do I need to escape forward slashes in the pattern field?
No. This tool passes your pattern directly to the RegExp constructor as a string, so you do not need to escape forward slashes. You only need to escape characters that are special inside regex syntax, such as . * + ? ( ) [ ] { } \\ ^ $ and |.
Is my data sent to a server?
No. This regex tester runs entirely in your browser using JavaScript's built-in RegExp object. Your pattern, test text, and replacement string are never transmitted anywhere.