Regex Tester
Test and debug regular expressions online. Find matches, use common patterns (email, URL, phone, IP, date, hex color), perform find-and-replace, and inspect capture groups.
Matches Found
—
Matched Values —
Pattern Valid —
Extended More scenarios, charts & detailed breakdown ▾
Match Count
—
Matches —
Pattern Status —
Professional Full parameters & maximum detail ▾
Match Results
Total Matches —
All Matches —
Capture Group 1 (first match) —
Replacement
After Replacement —
Pattern Info
Pattern Valid —
Test String Length —
How to Use This Calculator
- Enter your Regex Pattern (without surrounding slashes).
- Enter a Test String to match against.
- Choose Flags — use "gi" for global case-insensitive matching.
- The result shows total matches and all matched values.
- Use the Common Patterns tab for pre-built email, URL, phone, IP, date, and hex color patterns.
- Use the Find & Replace tab to perform regex substitutions.
Formula
JavaScript regex syntax: /pattern/flags. Key metacharacters: . any char, \d digit, \w word char, \s whitespace, ^ start, $ end, * 0+, + 1+, ? 0 or 1, {n,m} range, [abc] character class, (abc) capture group, (?:abc) non-capturing group.
Example
Email pattern: [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} → matches "user@example.com" in the string "Contact user@example.com for support".
Frequently Asked Questions
- A regular expression (regex) is a sequence of characters that defines a search pattern. Regex can match, extract, or replace text in strings. For example, \d+ matches one or more digits, and [a-z]+ matches one or more lowercase letters.
- g (global) finds all matches instead of stopping at the first. i (case-insensitive) matches regardless of letter case, so /hello/i matches "HELLO", "Hello", and "hello". m (multiline) makes ^ and $ match the start/end of each line rather than the entire string.
- Catastrophic backtracking happens when a regex engine tries an exponential number of path combinations to find a match, freezing the application. It typically occurs with nested quantifiers like (a+)+ on long non-matching strings. Use possessive quantifiers or atomic groups in supported engines to prevent it.
- PCRE (Perl-Compatible Regular Expressions) supports lookbehind with variable length, possessive quantifiers, and more advanced features. JavaScript (ECMAScript) regex follows the ECMA-262 standard, which is slightly more limited but has added features like named capture groups (?
) and lookbehind since ES2018. - Escape special characters with a backslash. Use \. for a literal dot (. alone matches any character). Use \( and \) for literal parentheses, \[ for a literal bracket, \* for a literal asterisk. In a character class [], most special characters lose their meaning except ] \ ^ -.
Related Calculators
Sources & References (5) ▾
- MDN Web Docs: Regular Expressions — Mozilla
- regex101 — Online Regex Tester & Debugger — regex101
- Mastering Regular Expressions, 3rd Ed. — O'Reilly / Friedl
- ECMAScript 2024 — RegExp Specification — TC39 / Ecma International
- Python re module documentation — Python Software Foundation