Regex Tester, Explainer & Debugger
Test JavaScript regular expressions online with live match highlighting, a token-by-token explanation of your pattern, and a per-match capture group table with spans. Supports all flags (g, i, m, s, u, y) — results update as you type.
About the Regex Tester & Debugger
The DevToolHeaven Regex Tester provides a live regular expression testing environment where matches are highlighted in real time as you type your pattern. No need to click a button — the tool updates on every keystroke, giving you instant feedback as you build and refine your expression.
Toggle regex flags individually: g (global) finds all matches, i (case-insensitive) ignores letter case, m (multiline) makes ^ and $ match line boundaries, s (dotAll) makes . match newlines, and u (unicode) enables full Unicode support for non-Latin scripts and emoji. Each flag can be toggled independently.
As you build a pattern, the Explanation panel breaks it down token by token and describes what each component does in plain English — anchors, character classes, quantifiers, groups, lookarounds, and backreferences. It is the fastest way to understand an unfamiliar expression or work out why your own pattern is not matching what you expect.
Switch to Replace mode to test how your pattern transforms text. Reference captured groups in the replacement string using $1, $2, or named groups with $<name>. The match information panel shows every match with its start position and length, plus a table of every capture group — by number or name — with the captured value and its exact span in the test string.
The Quick Reference panel provides one-click insertion of common real-world patterns: email addresses, URLs, IP addresses, phone numbers, dates, hex colors, HTML tags, and more. Use them as starting points and adapt them to your specific needs.
Regular expressions are used for: input validation (email, phone, postal code formats), extracting data from unstructured text (log parsing, web scraping), search-and-replace in text editors and scripts, URL routing in web frameworks, string tokenization in parsers, and data sanitization in processing pipelines.
All matching runs 100% client-side using JavaScript's built-in RegExp engine. Results are identical to what you would get running the same pattern in a browser or Node.js environment. Your test strings and patterns are never sent to any server.
Frequently Asked Questions
A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to find, match, extract, or replace text based on flexible pattern rules rather than exact string matching. Regex is supported in virtually every programming language.
g (global) finds all matches instead of stopping at the first. i (case-insensitive) makes the match ignore uppercase and lowercase differences. m (multiline) makes ^ and $ match the start and end of each line. s (dotAll) makes . match newlines too. u (unicode) enables full Unicode support.
Special regex characters like . * + ? ( ) [ ] { } \ ^ $ | must be escaped with a backslash to match literally. For example, to match a dot use \. and to match a plus sign use \+. The quick reference panel shows all special characters.
Capture groups are parts of a pattern wrapped in parentheses (). They capture the matched text for use in replacement strings or programmatic extraction. In the match results, each group is shown in a table below the match with its number (or name), the captured value, and the start–end span. Use (?:...) for non-capturing groups when you need grouping without capturing.
As you type a pattern, the Explanation panel breaks it down token by token and describes what each piece does in plain English — for example, \d means "any digit", + means "one or more times (greedy)", and (?<year>...) means "named capturing group". This makes it easy to learn an unfamiliar regex or debug one that is not matching what you expect, without reading a reference manual.
Each match in the Match Information panel lists every capture group in a table showing the group number or name, the captured text, and the exact start–end character positions (the span). Named groups like (?<id>\d+) appear with their name. Groups that did not participate in the match are clearly marked as "not matched" rather than shown as empty.
Switch to Replace mode and enter your replacement string below the test string. Use $1, $2 etc to reference captured groups in the replacement. For example, if your pattern is (\w+)\s(\w+) and replacement is $2 $1, it swaps the two words.
Common reasons for no matches: missing the g flag (finds only the first match), escaping issues (using . when you mean \.), case mismatch (add the i flag), anchors too restrictive (^ and $ only match line boundaries with m flag), or the pattern logic itself. Use the quick reference patterns as starting points.
Named capture groups use the syntax (?<name>...) to give a group a label in addition to a number. In replace mode, reference them as $<name>. In JavaScript code, access them via match.groups.name. Named groups make complex patterns self-documenting and are especially useful when a pattern has many groups.
By default, quantifiers like *, +, and ? are greedy — they match as much text as possible. Adding a ? after the quantifier makes it lazy — it matches as little as possible. For example, <.+> greedily matches the entire string "<b>text</b>" as one match, while <.+?> lazily matches "<b>" and "</b>" as two separate matches.
A commonly used pattern is: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/. This matches most valid email formats. Note that perfectly validating emails with regex is notoriously complex — the official RFC 5322 pattern is hundreds of characters long. For production use, a simple pattern plus server-side verification email is the recommended approach.
regex.test(string) returns a boolean — true if the pattern matches, false otherwise. It is fast and best for simple yes/no checks. string.match(regex) returns an array of matches (or null if no match) — use it when you need to extract the matched text or capture groups. With the g flag, match() returns all matches; without it, it returns the first match with group details.
Phone number formats vary widely by country, making a universal regex difficult. For US numbers: /^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/. For international numbers (E.164 format): /^\+[1-9]\d{6,14}$/. Test your specific format using the quick reference patterns in this tool, then adjust for your needs.
Use word boundary anchors \b before and after the word: /\bword\b/. This matches "word" as a standalone word but not as part of "keyword" or "password". \b matches at the transition between a word character (\w) and a non-word character. For example, /\bcat\b/ matches "cat" in "the cat sat" but not in "concatenate".