Development
Regex Cheat Sheet: Essential Regular Expressions for Beginners
A practical guide to the most useful regular expressions for text processing and validation.
Regular expressions (regex) are patterns used to match character combinations in strings. They are powerful tools for text processing, validation, and data extraction.
Basic Syntax
Anchors
- ^ — Start of string
- $ — End of string
- \b — Word boundary
Character Classes
- . — Any character except newline
- \d — Any digit (0-9)
- \w — Any word character (a-z, A-Z, 0-9, _)
- \s — Any whitespace
- [abc] — Any of a, b, or c
- [^abc] — Not a, b, or c
- [a-z] — Range from a to z
Quantifiers
-
- — 0 or more
-
- — 1 or more
- ? — 0 or 1
- {3} — Exactly 3
- {3,} — 3 or more
- {3,6} — Between 3 and 6
Useful Regex Patterns
Email Validation
Pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$
Phone Number (US)
Pattern: ^(?\d{3})?[-.\s]?\d{3}[-.\s]?\d{4}$
URL
Pattern: https?://[\w-]+(.[\w-]+)+[/\w-._~:?#[]@!$&()+,;=]
Strong Password
Pattern: ^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[@$!%?&])[A-Za-z\d@$!%?&]{8,}$
Requires: lowercase, uppercase, digit, special character, minimum 8 characters.
Tips for Using Regex
- Start simple and build up complexity
- Test your patterns with online regex testers
- Use non-capturing groups (?:…) when you do not need the match
- Comment complex patterns for future readability
- Use our Find & Replace tool with regex support for quick text processing
regexprogrammingtext
Need text tools?
Try our free online text tools for instant results.