Regex Tester
Test JavaScript regular expressions live with match highlighting.
About the Regex Tester
The Regex Tester & Visualizer lets you experiment with regular expressions against any test string and see exactly what matches — with the matched substrings highlighted in place and listed with their positions and capture groups. Whether you are debugging a phone-number pattern, building a log-parsing regex, or learning how capture groups work, this tool gives you instant feedback on what your pattern actually does (which is often different from what you think it does).
Regular expressions are a compact, powerful language for matching patterns in text. They appear in search (Google's regex search in Search Console), validation (email and phone patterns), parsing (log analysis, scraping), and substitution (find-and-replace with capture groups). They are notoriously hard to read — a complex regex can take minutes to understand — so a visual tester that shows exactly which substrings match is invaluable.
The tool supports all standard JavaScript regex flags: g (global, find all matches), i (case-insensitive), m (multiline, ^ and $ match line boundaries), s (dotall, . matches newlines), u (unicode, treat pattern as Unicode code points), and y (sticky, match only at lastIndex). Capture groups are reported with their contents so you can verify that your grouping is correct.
How It Works
The tool uses JavaScript's native RegExp constructor and exec() method. new RegExp(pattern, flags) compiles the pattern; if the syntax is invalid, it throws a SyntaxError which the tool catches and reports.
For global patterns (with the g flag), the tool calls re.exec(testString) repeatedly until it returns null. Each call returns a match object with the matched substring, the index where it was found, and any capture group contents (in match[1], match[2], etc.). A safety counter caps the loop at 10,000 iterations to prevent infinite loops on patterns that match empty strings (like /(?:)/g).
For non-global patterns, a single exec() call returns the first match (or null). The lastIndex property is not advanced, so calling exec() again returns the same match.
Highlighting is done by walking the matches in order and inserting <mark> tags around each matched substring in a copy of the test string. The offset is tracked because each insertion shifts the indices of subsequent matches by the length of the inserted markup.
Worked Examples
Default pattern \d+ with flag g against “abc 123 def 456 ghi 789” matches three substrings: “123” at index 4, “456” at index 12, and “789” at index 20. Each is highlighted in the test string and listed with its position.
Try a pattern with capture groups like (\w+)@(\w+\.\w+) against “Contact john@example.com or jane@test.org” with flag g. The tool matches both email addresses and shows, for each match, the captured username (group 1) and domain (group 2). This is the foundation of email extraction and parsing.
For phone number validation, try ^\+?[1-9]\d{1,14}$ (the E.164 international format) against various inputs: “+15551234567” matches, “555-123-4567” does not (hyphens are not allowed by this pattern). Removing the ^ and $ anchors would make the pattern match any substring containing 7-15 digits, which is usually not what you want for validation.
When to Use This Tool
- Debugging regex patterns that are not matching as expected.
- Validating user input (emails, phone numbers, postal codes, dates).
- Extracting structured data from log files (IPs, timestamps, status codes).
- Building web scraping patterns to extract prices, titles, or links.
- Testing find-and-replace patterns before applying them to real data.
- Learning how capture groups and lookarounds work.
- Verifying that a regex performs well (no catastrophic backtracking) on representative input.
Limitations & Disclaimer
This tool uses JavaScript's native RegExp (ECMAScript flavor) and does not support PCRE-specific features like recursion, conditional patterns, possessive quantifiers, or atomic groups. The safety counter caps matches at 10,000 to prevent infinite loops on empty-match patterns, but very high match counts (over 10,000) will be truncated. The highlighting inserts HTML <mark> tags, which may interact unexpectedly with HTML special characters in the test string (they are escaped before insertion). The tool does not detect catastrophic backtracking (ReDoS) — patterns like (a+)+b against “aaaaaaaaaaaaaaaaaaaa!” may hang the browser. See our disclaimer for full terms.
Frequently Asked Questions
Which regex flavor does this tool support?
The tool uses JavaScript's native <code>RegExp</code>, which is the ECMAScript flavor. It supports most modern features (lookaheads, named groups in ES2018+, the <code>s</code> dotall flag, the <code>u</code> unicode flag). It does not support some PCRE features like recursion, conditional patterns, or callouts. If your regex works in Node.js or modern browsers, it will work here.
What is the difference between /g and not using /g?
Without <code>g</code>, the regex finds only the first match. With <code>g</code>, it finds all matches. This affects both <code>exec()</code> (which advances <code>lastIndex</code> after each call when global) and <code>String.replace()</code> (which replaces only the first match without <code>g</code>, all matches with <code>g</code>).
Why does my pattern match nothing?
Common causes: missing anchors (the pattern matches but only inside a longer substring), case sensitivity (try adding the <code>i</code> flag), escaping issues (backslashes in the input are interpreted by JavaScript string parsing — use raw strings or double the backslashes), or character class mistakes (using <code>[a-z]</code> when you meant <code>[A-Za-z]</code> to match both cases).
What are capture groups and how do I use them?
Parentheses in a regex create capture groups that record the matched substring for later use. <code>(\d{3})-(\d{4})</code> captures the area code and local number separately. In the match list, group 1 is the first parenthesized match, group 2 is the second, etc. In replacement strings, refer to them as <code>$1</code>, <code>$2</code>, etc.
Can I use named capture groups?
Yes, in modern browsers (ES2018+). Use <code>(?<name>pattern)</code> to create a named group. The matched content is available on <code>match.groups.name</code> in the match object. Named groups improve readability for complex patterns with many groups.
Is my regex or test string uploaded anywhere?
No. All regex execution happens in your browser using JavaScript's native <code>RegExp</code>. Your patterns and test data — including any sensitive content — never leave your device.
Last updated: July 21, 2026 · Author: HT99 Tools Editorial Team · Reviewed by: HT99 Tools Editorial Team