Test Your Pattern
Regex Pattern Basics
Metacharacters define patterns:
.- Any character\d- Digit\w- Word character\s- Whitespace^$- Start/end anchors
Quantifiers control repetition: * zero+, + one+, ? optional, {n,m} between n and m.
Common Regex Patterns
| Pattern | Use |
|---|---|
[\w.-]+@[\w.-]+\.\w+ | |
\d{3}[-.]?\d{3}[-.]?\d{4} | Phone |
https?://[\w.-]+ | URL |
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} | IPv4 |
#[0-9A-Fa-f]{6} | Hex color |
Regex Flags
- g - Global, find all
- i - Case insensitive
- m - Multiline
- s - Dot matches newline
Advanced Patterns
(...) capture groups. ([a-z])\1 matches "aa". foo(?=bar) matches "foo" before "bar" (lookahead).