RegEx Tester & Debugger

Test and debug regular expressions in real-time. See matches highlighted with detailed explanations.

//g
About RegEx Tester

Test JavaScript-flavor regular expressions against sample text with instant match highlighting, capture-group inspection, and support for all common flags (g, i, m, s, u, y). Every match shows its start and end index plus any named or numbered groups — making it easy to debug tricky lookahead, backreference, or quantifier issues before you paste the pattern into your code.

Regular expressions are powerful and brittle in equal measure. A pattern that works on a sample can silently break on edge cases: an email address with a plus sign, a URL with Unicode, a multi-line string, a greedy quantifier that accidentally swallows too much. Testing against realistic input is the only way to be confident.

This tester uses the browser's native JavaScript regex engine — the same one that runs in Node.js, so what works here works in your code. Flags are independent: g matches all occurrences, i is case-insensitive, m makes ^ and $ match line boundaries, s makes . match newlines (dotAll), u enables Unicode mode (important for non-ASCII text and proper surrogate-pair handling), and y (sticky) forces matches to start at lastIndex.

For complex patterns, consider whether a regex is the right tool. If you're parsing HTML or JSON, use a proper parser — regex can get you 80% there but fails on nested structures. If you're doing input validation, consider whether a structural check (trim + split + length check) is easier to maintain than a dense expression.

How to use the RegEx Tester
  1. 1

    Write your pattern

    Enter the regex in the pattern field. The /slash delimiters/ are implicit — just type the pattern. Add flags separately.

  2. 2

    Paste test input

    Drop in sample text — the messier and more representative, the better. Include edge cases: empty lines, special characters, the boundaries of what you expect to match.

  3. 3

    Inspect matches and groups

    Each match is highlighted in the input. Click a match to see its start/end indices and the contents of every capture group.

  4. 4

    Tune flags and iterate

    Toggle flags (g, i, m, s, u, y) to see how they change the results. Once the pattern behaves correctly, copy it into your code.

Common use cases

Input validation

Write and test a regex for emails, phone numbers, or custom IDs before wiring it into a form validator.

Log parsing

Extract structured fields from free-form log lines — timestamps, error codes, user IDs — using named capture groups.

Search and replace

Prototype find-and-replace operations for large codebases or text files before running them in an editor.

URL routing patterns

Sanity-check URL patterns for a router or reverse proxy, making sure they match the right paths and nothing more.

Frequently asked questions
Which regex dialect does this use?

JavaScript / ECMAScript regex, same as what runs in Node.js and browsers. If you're writing Python, Go, PCRE, or .NET regex, syntax is similar but not identical — some features (like atomic groups or possessive quantifiers) don't exist in JavaScript.

Why doesn't my pattern find all matches?

You probably forgot the g (global) flag. Without it, regex methods stop after the first match. The tester shows only what the regex would actually return when called normally.

What's the difference between * and .*?

* is a quantifier — it means 'zero or more of the preceding element'. By itself it's invalid. .* means 'any character, zero or more times'. Use .*? (non-greedy) when you want the shortest match, otherwise the regex engine matches as much as possible.

How do I match across multiple lines?

For . to match newlines, enable the s (dotAll) flag. For ^ and $ to match the start and end of each line instead of the whole string, enable the m (multiline) flag. These are independent.

Can I run into infinite loops or catastrophic backtracking?

Yes — patterns with nested quantifiers on overlapping character classes can exhibit exponential backtracking on certain inputs, freezing the browser tab. If a match seems stuck, refresh and simplify the pattern. Avoid patterns like (a+)+b.

developervalidatortext