WebToolsPlanet
text Tools

Regex Tester

Test and debug regular expressions with live match highlighting, capture group display, and flag explanations — using JavaScript's native RegExp engine.

Last updated: March 25, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is Regex Tester?

Regular expressions (regex) are a compact pattern language for searching, matching, and transforming text — used in every programming language, text editor, database query system, and command-line tool. Despite their power, regex syntax is notoriously dense: a pattern like `^[\w.-]+@[\w-]+\.[a-zA-Z]{2,}$` can be hard to read and debug without seeing it applied to real test text in real time.

A regex tester provides immediate feedback: type a pattern in milliseconds and instantly see which parts of your test string match, which capture groups were extracted, the match positions (index offsets in the string), and how the pattern behaves with different flags (global, case-insensitive, multiline, dotAll). This shortens the regex development loop from a code-run-debug cycle to a live interactive session. The engine is JavaScript's native `RegExp`, which is also the engine used by Node.js, Deno, browsers, and any JavaScript runtime — making test results directly applicable to production code.

How to Use Regex Tester

1

Enter your regex pattern in the "Pattern" field (without surrounding forward slashes)

2

Select flags as needed using the flag toggles: g (global), i (ignore case), m (multiline), s (dotAll)

3

Type or paste your test string in the large "Test Input" area

4

Matches are highlighted in the test area in real time — each match outlined in colorful highlighting

5

The "Match Details" panel shows each match's full value, position index, and all named + numbered capture group values

Common Use Cases

  • Testing an email validation regex against a list of valid and invalid email addresses before using it in production
  • Debugging a URL extraction regex that's matching too many or too few URLs in a text block
  • Writing a date format parser regex and testing it against various date string formats (MM/DD/YYYY, YYYY-MM-DD)
  • Validating a phone number regex handles international formats (+1, 001, with/without dashes and parentheses)
  • Testing a log file parser regex against sample log lines before using it in a data pipeline
  • Building a search-and-replace regex for a text transformation script — previewing the replace output
  • Testing a markdown parser regex for bold (**text**) and italic (*text*) markers
  • Writing a regex for password complexity requirements and verifying it correctly flags weak passwords

Example Input and Output

Testing an email extraction regex against mixed text with multiple addresses:

Pattern + test input
Pattern: [\w.-]+@[\w-]+\.[a-zA-Z]{2,}
Flags: g (global)

Test input:
Contact us at support@example.com or
sales@company.co.uk. For press enquiries:
press.team@brand-name.org
Match results
✅ 3 matches found:

Match 1: "support@example.com"  (index 14–33)
Match 2: "sales@company.co.uk"  (index 37–56)
Match 3: "press.team@brand-name.org" (index 79–104)

No capture groups (non-capturing pattern)
→ In JS: text.match(/[\w.-]+@[\w-]+\.[a-zA-Z]{2,}/g)

Client-Side Processing

All regex testing runs in your browser using JavaScript's native RegExp engine. Patterns and test text are never sent to our servers.

Avoiding Regex ReDoS

ReDoS (Regular Expression Denial of Service) occurs when a regex with nested quantifiers causes exponential backtracking on adversarial input. Dangerous patterns: (a+)+ on "aaaaaaaaaab" — the engine tries all exponential combinations. To check: paste your pattern in this tester with a long repeated string that almost-matches. If the page freezes for >1 second, the pattern is vulnerable to ReDoS. Safe alternatives: atomic groups (not in JS), possessive quantifiers (not in JS), or restructuring the pattern to avoid nested repetition.

Named Capture Groups in Modern JS

ES2018 added named capture groups: (?<name>pattern). These are very readable: /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/.exec("2024-03-25").groups gives {year: "2024", month: "03", day: "25"}. In string.replace(), use $<name>: "2024-03-25".replace(..., "$<month>/$<day>/$<year>") → "03/25/2024". Supported in Chrome 64+, Firefox 78+, Safari 11.1+, Node.js 10+.

Frequently Asked Questions

What is the difference between the g flag and no g flag?
Without the g (global) flag: the regex matches only the first occurrence in the string, then stops. With the g flag: the regex finds all non-overlapping matches in the string. In JavaScript: "abc abc".match(/abc/) returns ["abc"] (one match). "abc abc".match(/abc/g) returns ["abc", "abc"] (two matches). For the i (ignoreCase) flag: patterns match both uppercase and lowercase — [A-Z] with i matches a–z too. For the m (multiline) flag: ^ and $ anchor to the start/end of each line rather than the whole string.
What are capture groups and how do I use them?
Capture groups (parentheses in a regex) extract specific parts of a match. Example: pattern (\d{4})-(\d{2})-(\d{2}) applied to "2024-03-25" captures: Group 1 = "2024", Group 2 = "03", Group 3 = "25". In JavaScript: const [full, year, month, day] = "2024-03-25".match(/(\d{4})-(\d{2})-(\d{2})/). Named capture groups: (?<year>\d{4}) — accessed as match.groups.year. Non-capturing groups (?:...) group without extracting — useful for quantifier scope without storing the value.
What special characters need to be escaped in a regex?
These characters have special meaning in regex and must be escaped with \ when you want to match them literally: . ^ $ * + ? { } [ ] \ | ( ). Example: to match a literal period, use \. (not . which matches any character). To match a literal parenthesis, use \( and \). To match a backslash itself, use \\. In JavaScript strings when passing to new RegExp(string), backslashes must be doubled: "\\d+" creates the regex \d+. When using regex literals /pattern/, a single backslash is sufficient.
How does the regex engine match (backtracking)?
Regex engines use backtracking: they try to match the pattern left-to-right, advancing through the string. When an optional or quantified part matches characters but the overall match then fails, the engine "backtracks" — gives up some of those characters and tries again. Example: for "aab" with pattern a*b, the engine first matches all "aa" with a*, then tries b — succeeds at position 2. For greedy patterns, the engine takes as many characters as possible, then backtracks. For lazy (*?), it takes as few as possible, then expands.
How do I match a newline character in a regex?
The . metacharacter does NOT match newlines by default. To match across lines: (1) Use the s (dotAll) flag in JavaScript (ES2018+): /hello.world/s matches newlines between "hello" and "world". (2) Use a character class that includes newlines: [\s\S] matches any character including newlines — this is the pre-ES2018 workaround. (3) Use the m (multiline) flag if you want ^ and $ to match line starts/ends rather than string start/end. These three flags are independent and can all be combined.
What is the difference between test(), match(), exec(), and replace()?
regex.test(string): returns true/false — fastest, for boolean "does this match?" checks. string.match(regex): returns array of matches (with g flag) or match object with capture groups (without g). regex.exec(string): returns one match object at a time, advances lastIndex with the g flag — useful for iterating over matches with a while loop. string.replace(regex, replacement): replaces matched text; use $1, $2 for capture groups or a function as replacement for dynamic values. string.matchAll(regex): returns an iterator of all match objects (requires g flag) — modern alternative to while + exec.

How This Tool Works

The pattern and flags are used to construct a JavaScript RegExp object: new RegExp(pattern, flags). For the test string, regex.exec() is called iteratively (or string.matchAll() for the g flag) to collect all match objects with their index positions and capture group values. Match positions are used to split the test string into non-matching and matching segments, which are rendered as spans with background highlights in the test input display. Capture group values are listed in the match details table below.

Technical Stack

JavaScript native RegExp engineString.prototype.matchAll()JavaScript named capture groupsClient-side only