Regex Syntax Quick Reference
Character Classes
- . - Any character except newline
- \\d - Digit (0-9)
- \\w - Word character (a-z, A-Z, 0-9, _)
- \\s - Whitespace (space, tab, newline)
- [abc] - Any of a, b, or c
- [^abc] - Not a, b, or c
Quantifiers
- \* - 0 or more
- + - 1 or more
- ? - 0 or 1
- {3} - Exactly 3
- {3,5} - Between 3 and 5
Anchors
- ^ - Start of string
- $ - End of string
- \\b - Word boundary
Common Regex Patterns
| Pattern | Description | Email patternEmail validation Phone patternUS Phone Zip patternUS Zip Code | URL pattern | URL Protocol |
Tips for Writing Regex
1. Start simple: Build patterns incrementally 2. Be specific: Avoid greedy patterns when possible 3. Use non-capturing groups: (?:...) when you don't need the capture 4. Escape special characters: . * + ? etc.