Regex Tester

Test JavaScript regular expressions with live match highlighting, capture group extraction, and full flag support (g, i, m, s).

Pattern
/ /
Test String
Common Patterns

Frequently Asked Questions

g (global) — find all matches (not just the first). i (case-insensitive) — treat uppercase and lowercase as equivalent. m (multiline) — make ^ and $ match the start and end of each line, not just the whole string. s (dotAll) — make . match newline characters (\n, \r) in addition to all other characters. Without s, . does not match newlines.
. matches any single character except newline (unless s flag). \d matches any digit [0–9]. \w matches a word character [a–zA–Z0–9_]. \s matches any whitespace character (space, tab, newline, carriage return). Their uppercase counterparts (\D, \W, \S) match the inverse — any non-digit, non-word, or non-whitespace character respectively.
A capture group is a portion of a regex enclosed in parentheses () that captures the matched substring for later use. Groups are numbered from 1 left to right. Example: (\d{4})-(\d{2})-(\d{2}) on "2024-01-15" captures "2024" in group 1, "01" in group 2, "15" in group 3. Named groups use (?<name>pattern) syntax. Non-capturing groups use (?:pattern) to group without capturing.
Greedy quantifiers (*, +, ?, {n,m}) match as much as possible. <.+> on <a> and <b> matches the entire <a> and <b>. Lazy (reluctant) quantifiers (*?, +?, ??, {n,m}?) match as little as possible. <.+?> on the same input matches only <a>. Use lazy quantifiers when you need to match the shortest possible string between delimiters.
Lookahead ((?=...)) asserts what comes after the current position without consuming characters. Example: \w+(?=\s+is) matches the word before "is". Negative lookahead ((?!...)) asserts that a pattern does NOT follow. Lookbehind ((?<=...)) asserts what comes before. Negative lookbehind ((?<!...)) asserts what does not come before. Lookbehind is supported in modern JavaScript (ES2018+) but not in older environments.
\b is a zero-width assertion that matches the position between a word character (\w) and a non-word character. It does not consume any characters. \bword\b matches the whole word "word" but not "password" or "wording". Use it to match complete words: \bcat\b matches "cat" in "the cat sat" but not in "concatenate".
Escape the special character with a backslash \. The special characters that need escaping in regex are: . * + ? ^ $ { } [ ] | ( ) \. Example: to match a literal period, use \. instead of .. To match a literal dollar sign, use \$. When building regex from user input in code, use a function to escape all special characters: str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').
Catastrophic backtracking (ReDoS) occurs when a regex with nested quantifiers takes exponential time to fail. Example: (a+)+b against a long string of "a"s with no "b" — the engine tries an exponential number of grouping combinations before giving up. Mitigation: avoid nested quantifiers with overlapping possibilities, use atomic groups or possessive quantifiers where available, and validate user-supplied regex patterns before applying them to untrusted input. Use this tester to measure performance before production use.
JavaScript regex (ECMAScript) lacks some features found in PCRE and Python: no recursive patterns, no conditional patterns, no branch reset groups, no possessive quantifiers (though atomic groups were added in ES2022 via (?>...)). JavaScript added named capture groups ((?<name>)), lookbehind, and s (dotAll) flag in ES2018. JavaScript's u flag enables full Unicode mode. This tester uses JavaScript regex — patterns from other flavors may behave differently.
Use the m (multiline) flag to make ^ and $ match the start and end of each line. Use the g (global) flag with String.matchAll() to find all occurrences across lines. To match content spanning multiple lines, use the s (dotAll) flag to make . match newlines, or use [\s\S] as a universally compatible alternative. Example: /^start[\s\S]*?end$/m matches from "start" to "end" across lines.

About This Regex Tester

This free regex tester tests JavaScript regular expressions with real-time match highlighting and capture group extraction. All matching runs in your browser using the native JavaScript regex engine — no data is sent to any server.

When to use this tool

  • Building and testing patterns for input validation
  • Debugging regex patterns that don't match as expected
  • Exploring capture groups and backreferences
  • Testing regex flags (global, case-insensitive, multiline, dotAll)

Related Articles

In-depth guides and technical articles.

View all →
Missing a Regex Anchor Is a Bug — Why ^, $, and \b Work Differently Than You Think in Multiline Mode
The difference between a regex that matches "digits" and one that matches "only digits" is anchor characters — and missing anchors are why input validators accept strings they should reject. Here's how ^ and $ change behavior in multiline mode (a security-relevant surprise), why \b word boundaries break on Unicode text, the \z vs $ distinction for absolute string-end matching in Python, and why unanchored authorization patterns misclassify URLs.
Regex Readability: How Verbose Mode and Named Capture Groups Turn a Mystery Into Documentation
Two regexes can match identical strings while one takes 30 seconds to understand and the other takes 10 minutes — and the difference is almost always structural, not functional. Here's how verbose/extended mode adds comments and whitespace to patterns, why named capture groups document intent within the pattern itself, a mental library of common recognizable patterns, and when a single complex regex should be replaced with simpler sequential operations instead.
Named Capture Groups, Lookahead, and Lookbehind: Modern Regex Features That Make Patterns Readable
Named capture groups turn regex matches from numbered tuples into readable dictionaries. Lookahead and lookbehind assertions match positions without consuming characters. Here's the modern regex feature set — named groups, non-capturing groups, all four assertion types — with practical patterns for log parsing and URL extraction.
ReDoS: How Catastrophic Backtracking in a Single Regex Can Take Down a Server
A single regex with a crafted input knocked Stack Overflow offline for 34 minutes and caused a global Cloudflare outage. Here's how catastrophic backtracking works, which patterns are vulnerable, how to test for ReDoS, and how to write safe alternatives.
Regex Patterns Every Developer Should Have: A Practical Reference
A practical reference of the regex patterns developers actually need — email, URL, UUID, IP address, dates, semver, hex colours, slugs, and more — with edge cases and caveats for each.