Developer Tool

Regex Tester & Visualizer

Solve "Write-Once, Read-Never" regex problems.
Real-time testing, explanation, and code generation in one place.

/^\d{5}$/
90210
Zip Code OK
/ /
{{ errorMsg }}
Unit Tests
{{ test.shouldMatch ? 'Match' : 'Miss' }}
*Checks if each line matches as expected.
Real-time Check
{{ sandboxMatches.length }} matches found:

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 }}
Library
Code Gen
Click to insert:
Email Address
US Zip Code
US Phone No.
Date (YYYY-MM-DD)
URL
Strong Password
const regex = /{{regexPattern}}/{{flags}};
const result = regex.test(str);
preg_match('/{{regexPattern}}/{{flags}}', $str);
import re
pattern = re.compile(r'{{regexPattern}}')

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.

Always double-check the specific documentation for your target language.