Developer Tool

Regex Tester & Visualizer

Test, explain, and debug regular expressions in real time.

Highlight every match and capture group, get a plain-English breakdown of your pattern, and copy ready-to-use JavaScript, PHP, or Python code.

/ /
{{ errorMsg || timeoutMsg }}
Unit Tests
{{ test.shouldMatch ? 'Match' : 'Miss' }}
*Checks if each line matches as expected.
Real-time Check
{{ sandboxMatches.length }} {{ sandboxMatches.length === 1 ? 'match' : 'matches' }} found ({{ zeroWidthCount }} zero-length) (showing the first 5,000):

Structure Visualizer

Enter a regex pattern to see its structure.

Explanation

{{ item.token }} {{ item.desc }} {{ item.group }}
Explanation will appear here.

Capture Groups ($1, $2...)

# Content
${{ i + 1 }} {{ g }}
Click to insert:
Email Address
US Zip Code
US Phone No.
Date (YYYY-MM-DD)
URL
Strong Password
{{ codeSnippets.js }}
{{ codeSnippets.php }}
{{ codeSnippets.python }}
  • {{ note }}

Matching uses the JavaScript regex engine. Some syntax, such as lookbehinds or Unicode property escapes, isn't supported in every language.

Common Tokens

Regex Cheat Sheet & Basic Rules

A quick reference for common regular expression metacharacters and syntax. Bookmark this for your development needs.

1. Special Characters (Metacharacters)

SymbolMeaningExample
.Any character (except newline)a.c → abc, aXc
\dDigit (0-9)\d{3} → 123
\wWord character [a-zA-Z0-9_]\w+ → user_id
\sWhitespace (space, tab, newline)
[ ]Character class (any of these)[abc] → a, b, or c
[^ ]Negation (not these)[^0-9] → Non-digit
|OR (Alternative)jpg|png
\Escape character\. → Literal dot

2. Quantifiers (Repetition)

SymbolMeaningExample
*0 or more timesa* → (empty), a, aa...
+1 or more timesa+ → a, aa, aaa...
?0 or 1 time (Optional)https? → http, https
{n}Exactly n times\d{4} → 2025
{n,}n or more times\d{8,} → 8+ digits
{n,m}Between n and m times\d{2,4} → 2 to 4 digits

3. Anchors (Position)

SymbolMeaningExample
^Start of line/string^http → Starts with http
$End of line/stringjpg$ → Ends with jpg

4. Flags (Options)

Options specified after the regex pattern (e.g., /pattern/g). You can input these in the small box to the right.

FlagNameBehavior
gGlobalFind all matches rather than stopping after the first match.
iIgnore CaseCase-insensitive search (matches both 'A' and 'a').
mMultiline^ and $ match start/end of each line, not just the whole string.

Useful Regex Snippets (Top 10)

Use CasePatternNote
Email^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$Basic validation
US Zip Code^\d{5}(-\d{4})?$5 digits or 5+4
Phone (US)^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$Allows (123) 456-7890
Date (ISO)^\d{4}-\d{2}-\d{2}$YYYY-MM-DD
URLhttps?://[\w!?/+\-_~=;.,*&@#$%()'[\]]+Starts with http/s
Password (Strong)^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$8+ chars, upper, lower, digit
Username^[a-zA-Z0-9_-]{3,16}$Alphanumeric, 3-16 chars
Integer^\d+$Numbers only
Hex Color^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$#ffffff or #fff
Slug^[a-z0-9]+(?:-[a-z0-9]+)*$URL-friendly text

FAQ

Why does it only match the first occurrence?

By default, Regex stops searching after finding the first match. To find all instances in the text, you must enable the Global flag. Enter g in the small input box on the right side of the main regex input.

What are "Capture Groups"?

Capture groups are parts of your pattern enclosed in parentheses ( ). They allow you to isolate and extract specific parts of the matched text.

For example, in the pattern (\d{4})-(\d{2}), $1 would contain the year and $2 would contain the month. This is useful for data extraction and replacement.

Is the code valid for all languages?

This tool runs in the browser and uses the JavaScript regex engine. While basic syntax (like \d, +, *) is standard across PHP, Python, and Java, some advanced features (like lookbehinds) may differ.

The code generator converts g to preg_match_all and other flags to modifiers for PHP, and rewrites named groups (?<name>) as (?P<name>) and flags as re.IGNORECASE and friends for Python. Always double-check the documentation for your target language.

Why does test() return true, then false, with the g flag?

With the g (or y) flag, a JavaScript RegExp remembers where the last match ended in lastIndex and starts the next search from there. Running /a/g.test('a') three times on the same object returns true → false → true.

This tool creates a fresh regex for every unit test, so the results never depend on the order you run them. In your own code, drop the g flag for simple checks or set regex.lastIndex = 0 before calling test().

Can a regex freeze the page?

Patterns with nested quantifiers such as (a+)+ can trigger catastrophic backtracking: on a string that almost matches, the work grows exponentially.

This tool runs matching in a separate thread (a Web Worker) and stops it after 1.5 seconds, then shows a warning so you can rewrite the pattern. The page stays responsive the whole time.