Regex Tester & Debugger

Test and debug regular expressions with real-time match highlighting, find-and-replace substitution, pattern explanation, captured groups, common pattern library, and a quick reference. Supports all JavaScript regex flags.

Loading tool...

How to Use This Tool

  1. 1

    Enter your regular expression pattern in the pattern field at the top. The delimiters / / are shown for you — just type the pattern itself. Or click Patterns to load a common pattern like email, URL, or phone number.

  2. 2

    Toggle flags using the buttons below the pattern: g (global — find all matches), i (case insensitive), m (multiline — ^ and $ match line boundaries), s (dotall — . matches newlines), and u (Unicode).

  3. 3

    Type or paste your test string into the test string area. Matches are highlighted in real time as you type.

  4. 4

    Use the Match Details tab to inspect each match's full text, index position, and any captured groups. Switch to the Substitution tab to test find-and-replace, or the Explanation tab to see a plain-English breakdown of your pattern.

  5. 5

    Use the Quick Reference panel at the bottom for a reminder of common regex tokens, substitution syntax, and their meanings.

What is Regex?

A regular expression (regex or regexp) is a sequence of characters that defines a search pattern. Originally formalised by mathematician Stephen Cole Kleene in the 1950s and popularised by Unix text-processing tools like grep and sed, regular expressions have become an indispensable tool in every programmer's toolkit. They are used for input validation (email addresses, phone numbers, passwords), search-and-replace operations, log parsing, data extraction, and virtually any task that involves matching patterns in text.

A regex pattern is built from literal characters and metacharacters. Literal characters match themselves — the pattern "cat" matches the string "cat". Metacharacters like . (any character), * (zero or more), + (one or more), ? (optional), ^ (start), and $ (end) give patterns their expressive power. Character classes like [a-z] match ranges, shorthand classes like \d (digit), \w (word character), and \s (whitespace) provide common shortcuts, and groups — both capturing (...) and non-capturing (?:...) — let you extract sub-matches and apply quantifiers to compound expressions.

Testing regular expressions interactively is essential because regex syntax is notoriously dense and easy to get wrong. A misplaced quantifier, a forgotten escape, or an unintended greedy match can produce subtle bugs that are hard to catch by reading the pattern alone. A regex tester gives you instant visual feedback: you see exactly what your pattern matches (and doesn't match) against real test data, inspect captured groups and their indices, and iterate quickly until the pattern behaves correctly. The substitution panel lets you test find-and-replace operations using back-references like $1 and named groups, while the explanation tab breaks your pattern into color-coded tokens with plain-English descriptions of each part. This tool runs entirely in your browser using JavaScript's built-in RegExp engine, so your data never leaves your machine.

Frequently Asked Questions

helpIs my data sent to a server?

No. All pattern matching, substitution, and explanation runs entirely in your browser using JavaScript's built-in RegExp engine. Your patterns and test strings never leave your device.

helpWhich regex engine does this tool use?

This tool uses JavaScript's native RegExp engine (the same engine used in all major browsers and Node.js). Regex syntax varies slightly between engines — for example, JavaScript does not support atomic groups or possessive quantifiers that are available in PCRE (Perl Compatible Regular Expressions). If you need to test patterns for a different engine, verify edge cases in that language's environment.

helpHow does the substitution feature work?

The Substitution tab lets you enter a replacement string and see the result of applying your regex as a find-and-replace operation. Use $1, $2, etc. to insert captured groups, $& for the entire match, $` for text before the match, and $' for text after. For named groups, use $<name>. Enable the global (g) flag to replace all occurrences.

helpWhat is the difference between the g and m flags?

The g (global) flag tells the regex to find all matches in the string, not just the first one. The m (multiline) flag changes the behaviour of ^ and $ so they match the start and end of each line (separated by \n), not just the start and end of the entire string. These flags are independent — you can use both together.

helpWhy does my pattern match more than I expected?

The most common cause is greedy quantifiers. By default, * and + match as much text as possible. Add a ? after the quantifier (e.g., .*? or .+?) to make it lazy — it will match as little text as possible. Another common issue is forgetting to anchor the pattern with ^ and $, which causes partial matches within longer strings.

helpHow do I match a literal dot, asterisk, or other special character?

Prefix the special character with a backslash to escape it. For example, \. matches a literal period, \* matches a literal asterisk, and \( matches a literal opening parenthesis. Inside a character class [ ], most special characters lose their special meaning and don't need escaping (except ], \, ^, and -).

Related Tools