Regex Tester
Test JavaScript regular expressions locally with g/i/m/s/u/y flags, match counts, line-column ranges, capture groups, named groups, and native replace preview.
/
/g
Test Text
Characters
0 / 50,000
Match Results
Enter a pattern to start matching
Replacement
Characters
0 / 50,000
Replacement Preview
Quick Start
Common Scenarios
Data extraction
use (\\d{4}-\\d{2}-\\d{2}) to extract dates, and ([\\w.]+@[\\w.]+) to extract email addresses
Format validation
write a regex, paste multiple samples, and quickly verify whether the pattern precisely matches the target format
Batch replacement
use capture groups to restructure content. For example, convert "First Last" to "Last, First" with pattern (\\S+)\\s+(\\S+) and replacement $2, $1
Named groups
use (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) to extract dates, then use $<year>/$<month>/$<day> to rebuild them
Regex learning
try different patterns and observe matching behavior to understand quantifiers, anchors, and character classes visually
Multi-line handling
enable the m flag so ^ and $ match by line, useful for logs, code, and configuration files
Usage Advice
Limitations & Compatibility
Privacy & Security
FAQ
A regular expression (regex) is a pattern language for describing text structures. Think of it as an "advanced search" — instead of searching for a fixed word, you search for everything matching a rule.\n\nFor example, \\d{4}-\\d{2}-\\d{2} matches all dates in YYYY-MM-DD format, and [\\w.]+@[\\w.]+ matches email addresses. Regex is widely used for: text search & extraction (finding error codes in logs), format validation (checking phone numbers), and batch replacement (converting date formats).\n\nAlmost every programming language (JavaScript, Python, Java, Go, etc.) and many tools (VS Code, grep, sed) support regex with mostly similar syntax. This tool uses the JavaScript RegExp engine for quick online testing and learning.
JavaScript regex returns only the first match by default — this is a language specification behavior, not a tool limitation. Click the g button in the flags bar to enable global search and see all matches.\n\nNote the interaction between g and y: g scans the entire text from start to end, while y (sticky) requires each match to start exactly where the previous one ended — if there are gap characters between matches, y stops at the first gap. Usually just enabling g without y is sufficient.
The usual causes are: 1. Unmatched brackets: every ( needs a matching ), and every [ needs a matching ]. Editors may auto-complete them, but this tool tests the pattern exactly as entered. 2. Quantifiers in the wrong place: *, +, ?, and {n} must follow something repeatable. Combinations like *+ or ?* are invalid; lazy quantifiers are written as *? or +?. 3. Incomplete escapes: a lone \ at the end is invalid. Escape a specific character, such as \d, \n, or \\. 4. Unicode properties without the u flag: \p{L}, \p{Script=Han}, and similar property escapes require u in this tool.
These references come from JavaScript's String.prototype.replace(): - $1, $2, ..., $99: the content of the corresponding capture group. - $&: the full match. - $`: the text before the match. - $': the text after the match. - $<name>: the content of a named capture group (?<name>...). For example, if (\w+)\s(\w+) matches "hello world", replacing with $2-$1 produces "world-hello". To include a literal $ in the replacement text, write $$.
Regex engines differ across languages in three main areas: 1. Syntax support: JavaScript does not support PCRE recursion (?R), conditional branches (?(cond)yes|no), or atomic groups (?>...). Python's re module also lacks them, while the third-party regex module supports some. Java supports atomic groups, but not recursion. 2. Unicode handling: in JavaScript, \w mostly means basic Latin letters, digits, and underscore. The u flag does not make \w match Chinese characters automatically. For Unicode letters, use property escapes such as \p{L} with the u flag. 3. Newlines: in Python, . does not match \n by default, just like JavaScript. Java Pattern.DOTALL is similar to JavaScript's s flag. Use this tool for quick JavaScript RegExp checks, then confirm with the target language's actual engine.