Regex Tester
Test JavaScript regular expressions with live highlighting, match positions and capture groups.
A regex tester that runs real JavaScript
You have a pattern and some sample text, and you want to know exactly what it matches before it goes into your code. This tester passes your pattern and flags to JavaScript's new RegExp() in your browser and runs it over the test string, so the matches you see are the ones your JavaScript will find.
The tester highlights every match in the text and lists it with its index and capture groups. Results update on every keystroke, so you can change a pattern one character at a time and watch the match list change.
Features
- Uses your browser's own JavaScript RegExp engine
- Live highlighting of every match as you type
- Match count and the index of each match
- Capture groups listed as $1, $2 and so on
- Toggle the g, i, m, s and u flags
- Syntax errors shown with the engine's message
- Copy the pattern as a /pattern/flags literal
- Pattern and text stay in your browser
How to test a regex online
- 1
Type the pattern
Enter your regular expression in the Regular Expression field. Leave out the surrounding slashes: they are shown for you, with the active flags after the closing slash.
- 2
Choose flags
Click a flag button to switch that flag on or off. The buttons are Global (g), Case Insensitive (i), Multiline (m), Dotall (s) and Unicode (u). Global is on by default.
- 3
Paste your test text
Type or paste the text to search into the Test String box. It can span several lines.
- 4
Read the matches
The Highlighted Matches panel marks each match as you type. Match Details lists each match with its index and capture groups, or shows No matches found. A syntax error appears as Invalid regex with the browser's message.
- 5
Copy the regex literal
Click the copy button beside the pattern field to copy the pattern as a JavaScript literal, such as /\d+/g, ready to paste into your code.
Worked examples to try
Copy a pattern into the Regular Expression field, set the flags shown, and paste the test text. This page shows line breaks in the test text as ↵.
Pull numbers out of text
/\d+/g
Text: Order 66 shipped 3 items
2 matches: 66 at index 6 and 3 at index 17.
Split a date into parts
/(\d{4})-(\d{2})-(\d{2})/g
Text: Due 2026-10-26, paid 2026-11-02
2 matches. The first has $1: 2026, $2: 10, $3: 26; the second has $1: 2026, $2: 11, $3: 02.
Find whole lines in a log
/^ERROR.*$/gm
Text: INFO start ↵ ERROR disk full ↵ WARN slow ↵ ERROR timeout
2 matches: ERROR disk full and ERROR timeout. Turn m off and nothing matches, because ^ and $ then mean the start and end of the whole text.
Match a word in any case
/\bjavascript\b/gi
Text: JavaScript and javascript, not JavaScripts
2 matches. The \b word boundaries stop it matching inside JavaScripts.
Greedy versus lazy
/<.+?>/g
Text: <b>bold</b>
2 matches: <b> and </b>. The greedy <.+> instead makes one match covering the whole string.
Optional group
/(https?)://([^/\s]+)(/\S*)?/g
Text: See https://speedytools.dev/tools or http://example.com
2 matches. The second URL has no path, so its $3 is shown as (empty).
Simple email finder
/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g
Text: Mail ana.k+news@example.co.uk or bob@site.dev
2 matches. (?:...) groups without capturing, so Match Details lists no $1. Good for finding addresses, not for strict validation.
Lookbehind for prices
/(?<=\$)\d+(?:\.\d{2})?/g
Text: Total: $42.50, tax $3
2 matches: 42.50 and 3. The lookbehind checks for the $ sign but leaves it out of the match.
Testing a pattern in JavaScript code
Once the pattern works here, use the copy button to get it as a literal. In JavaScript, regex.test(text) answers yes or no, text.match(regex) returns the matches, and regex.exec(text) returns one match at a time with its index and groups, which is what this tester uses.
/^\d{3}-\d{4}$/.test("555-0199"); // true
/^\d{3}-\d{4}$/.test("call 555-0199"); // falseTo validate a whole value, anchor the pattern with ^ and $. Without them, test() returns true if the pattern matches anywhere in the string.
Be careful calling test() on a regex that has the g flag. It remembers where the last match ended in lastIndex, so with const re = /\d/g, calling re.test("a1b2") three times returns true, true, then false. Drop the g flag when you only need a yes or no answer.
The five flags
- g Global
- Finds every match instead of stopping at the first one. On by default.
- i Case Insensitive
- Treats upper and lower case letters as the same.
- m Multiline
- Makes ^ and $ match at the start and end of each line, not only the whole text.
- s Dotall
- Lets . match line breaks as well. Without it, a.c does not match a, newline, c.
- u Unicode
- Enables Unicode escapes such as \p{Lu} (any uppercase letter) and makes unknown escapes an error. Without u, \p{Lu} matches the literal text p{Lu}.
The y (sticky), d (indices) and v (unicode sets) flags have no button here, and you cannot add them.
Limitations to know about
- JavaScript syntax only. Patterns written for Python, PHP (PCRE), Java or .NET may need changes. Some differences raise an error, like (?P<name>...) or possessive a++, but some do not. Without the u flag, the engine accepts \A and \Z and matches them as the letters A and Z.
- No performance testing. The tester does not time patterns, and a pattern with catastrophic backtracking can freeze the tab because matching runs on every keystroke.
- Match Details lists named groups by number, not by name. A group that did not take part in a match shows as (empty).
- Patterns that can match empty text, like \d*, also report zero-length matches, so \d* against a1 gives three matches: an empty one at index 0, 1 at index 1 and an empty one at index 2.
- There is no replace or split mode, and no explanation of what each part of the pattern means.
- The copied literal is /pattern/flags exactly as typed. If your pattern contains a forward slash, write it as \/ so the literal stays valid in code.
Your text stays in your browser
There is no server step. Matching is done by JavaScript in your browser tab, so you can test patterns against log lines or other text you would rather not paste into a website that uploads it. The page records anonymous usage events, such as which flag you toggled and the length of a copied pattern, but never the pattern or the test string.
Frequently asked questions
How do I test a regex pattern in JavaScript?
In code, call pattern.test(text), for example /^\d{3}-\d{4}$/.test("555-0199"), which returns true or false. To see what matched and where, type the pattern (without the surrounding slashes) into the tester above, paste your text into Test String, and read the highlighted matches, their index and capture groups.
Which regex flavour does this tester use?
JavaScript. The tester passes your pattern to new RegExp() in your browser, so it behaves exactly as it would in your browser's JavaScript. Syntax from other flavours, such as Python's (?P<name>...) groups or PCRE atomic groups (?>...), makes the tester show Invalid regex.
Which regex flags are supported?
There are toggle buttons for g (global), i (case insensitive), m (multiline), s (dotall) and u (unicode). Global is on by default. The y (sticky), d (indices) and v (unicode sets) flags are not available in this tester.
Why does my regex only find one match?
The g flag is probably off. Without it the tester, like JavaScript's exec() and match(), returns only the first match. Turn on the Global flag, g, to list every match in the text.
Can this tool measure regex performance?
No. It does not time patterns or count backtracking steps. Matching runs on every keystroke in your browser tab, so a pattern with catastrophic backtracking, such as (a+)+$ against a long run of a's followed by another character, can make the page freeze. To benchmark a pattern, time it in your own code with console.time() or performance.now().
Is my test text sent to a server?
No. JavaScript in your browser matches the pattern against the test string. The page records anonymous usage events, such as which flag you toggled and the length of a copied pattern, but not the pattern or the text.
Does it support named capture groups and lookbehind?
Yes, if your browser's JavaScript engine supports them, and current browsers support both. Named groups such as (?<year>\d{4}) match normally, but the Match Details list shows every group by number ($1, $2 and so on) rather than by name.
Related tools
JSON Formatter
Format JSON online in your browser. Paste or upload JSON to tidy it with 2 or 4 space indents, find syntax errors, minify it or browse it as a collapsible tree.
JavaScript to JSON
Convert JavaScript object literals to valid JSON
JSON Merge
Merge two JSON objects online with a deep or shallow strategy and choose how arrays combine. Useful for config files and API responses. Free, no signup.