Regex Tester & Debugger

Answer: The Regex Tester & Debugger produces your output instantly from the input you provide — everything runs in your browser, free, with no signup required.

Test regular expressions with real-time match highlighting

Ad
/ /
0 matches
Quick Reference
. Any character
\d Digit [0-9]
\w Word character
\s Whitespace
^ Start of string
$ End of string
* 0 or more
+ 1 or more
? 0 or 1
{n,m} n to m repeats
[abc] Character set
(...) Capture group
Ad

About the Regex Tester

This regex tester evaluates your patterns live against sample text, highlighting matches, capture groups, and boundaries as you type. It uses your browser's JavaScript regex engine, so behavior matches what your web code will actually do.

Regular expressions are a miniature language for describing text shapes. Ten or so concepts cover ninety percent of practical regex — and knowing them beats memorizing patterns.

Because the tester runs entirely in your browser, nothing you type is uploaded, and results appear on every keystroke with no submit button. Paste a log excerpt, a CSV line, or a user-submitted form field into the test string area, then iterate on the pattern until the highlights land exactly where you expect. Capture groups appear below the matches so you can confirm each group grabs the right slice of text before the pattern ships into production code.

The Building Blocks of Regex

Character classes match sets: \d (digits), \w (word characters), \s (whitespace), and negations \D, \W, \S. The dot matches any character except newline. Anchors position rather than consume: ^ start of line/string, $ end, \b word boundary.

Quantifiers repeat: * (zero or more), + (one or more), ? (optional), and {n,m} (between n and m). Alternation with | offers choices, and parentheses capture for reuse — either in replace patterns ($1) or back-references (\1). Flags change meaning: i (case-insensitive), g (all matches), m (^/$ per line).

Cheat Sheet: The Workhorse Patterns

The table lists the patterns that solve most everyday tasks, each with a concrete example match. These follow standard syntax shared by JavaScript, Python, and PCRE.

Compose them: an email shape check like [\w.+-]+@[\w-]+\.[\w.]+ catches obvious typos (missing @ or TLD) while deliberately not attempting full RFC 5322 validation, which is famously impractical — the spec permits addresses no simple pattern accepts.

PatternExample matchUse
\d{3}-\d{4}555-1234Phone-style segment
[\w.+-]+@[\w-]+\.[\w.]+user@example.comEmail shape check
^https?://[^\s/$.?#].[^\s]*$https://example.comURL shape (Fleischman/Gruber style)
\b\d{1,3}(\.\d{1,3}){3}\b192.168.1.1IPv4 shape
^(\d{4})-(\d{2})-(\d{2})$2026-08-26ISO date with capture groups
(?i)\berror\bERROR: failedCase-insensitive flag (inline)

Greediness, Backtracking, and Catastrophe

Quantifiers are greedy by default: <.*> on '' matches the whole string because .* stretches to the last '>' — add ? for the lazy version (<.*?>) that stops at the first. This greedy/lazy distinction is the most common regex bug.

Nested quantifiers like (a+)+ can trigger catastrophic backtracking — exponentially many retry paths on a non-matching input — which freezes engines and ReDoS-vulnerable websites. Keep quantifiers non-overlapping and prefer explicit character classes (e.g. [^<]* instead of .*) when a delimiter exists.

Regex vs. Parsing, and Testing Discipline

Regex cannot parse nested structures (HTML, JSON, arithmetic) because regular languages don't support recursion — the classic admonition is to not parse HTML with regex. Use regex to find tokens, then a real parser for structure.

Test discipline: always include should-match AND should-NOT-match cases, boundaries (empty string, unicode, accents), and the pathological backtracking input if your pattern has adjacent quantifiers. This tool shows every match with its groups, making misses visible at a glance.

Regex Across Languages and Flags

['Regex syntax is mostly portable, but engines differ: JavaScript supports lookbehind in modern browsers, named groups as (?...), and the s flag (dot matches newline); Python uses (?P...) naming and re.VERBOSE; PCRE adds recursion. When a pattern works here but not in your runtime, flags and lookarounds are the first suspects.', "The global flag changes everything in JavaScript: without /g, .match() returns only the first match (with groups); with /g, it returns all matched strings (without groups). The /u flag enables full Unicode handling, including emoji — without it, surrogate pairs split characters mid-symbol. Test emoji and accented input explicitly; it's where engines disagree most.", "Real-world habit: keep patterns short, name the intent with comments (Python's VERBOSE or free-spacing in JS via construction), and unit-test them like code — because they are code. A three-line test file of should-match and should-reject strings catches regressions the moment someone 'improves' the pattern."]

Frequently Asked Questions

What does \d mean in regex?

\d matches any single digit (0-9). Its negation \D matches any non-digit. Related: \w matches word characters (letters, digits, underscore), \s matches whitespace, each with an uppercase negation.

What's the difference between * and +?

* matches zero or more of the preceding element; + requires at least one. So a* matches the empty string but a+ does not. Both are greedy — add ? (*?, +?) for lazy matching that stops at the first opportunity.

How do I test if a string matches a regex in JavaScript?

Use /pattern/.test(string) for a boolean, or string.match(/pattern/g) to get all matches. This tester runs the same JavaScript engine, so results here equal results in your code.

What is catastrophic backtracking?

When nested quantifiers like (a+)+ fail to match, the engine retries exponentially many sub-paths, hanging the process. Avoid adjacent ambiguous quantifiers and prefer bounded classes like [^x]* — the vulnerability class is known as ReDoS.

Can regex parse HTML or JSON?

No. Regular expressions cannot handle arbitrary nesting — that requires a context-free grammar and a real parser. Regex is fine for finding tokens inside HTML (like an attribute value) but not for validating document structure.