Developmentβ’
2026-02-19
β’10 min
β’alltools.one Team
regexregular-expressionsdevelopmentpatternsvalidation
Regex Cheat Sheet: Patterns Every Developer Needs
Regular expressions feel like dark magic until you learn the patterns. Once you do, they become indispensable for text search, validation, data extraction, and string manipulation.
Grab a pattern, paste it into our Regex Tester to experiment, and adapt it to your needs.
Core Regex Syntax
Character Classes
| Pattern | Matches | Example |
|---|---|---|
. | Any character except newline | a.c matches "abc", "a1c" |
\d | Any digit (0-9) | \d{3} matches "123" |
\w | Word character (letter, digit, underscore) | \w+ matches "hello_1" |
\s | Whitespace | \s+ matches spaces |
[abc] | Any one of a, b, or c | [aeiou] matches vowels |
[^abc] | Any character except a, b, c | [^0-9] matches non-digits |
[a-z] | Any character in range | [A-Za-z] matches letters |
Quantifiers
| Pattern | Meaning |
|---|---|
* | Zero or more |
+ | One or more |
? | Zero or one |
{n} | Exactly n times |
{n,m} | Between n and m times |
Anchors and Groups
| Pattern | Meaning |
|---|---|
^ | Start of string |
$ | End of string |
\b | Word boundary |
(abc) | Capturing group |
(?:abc) | Non-capturing group |
a|b | Alternation (or) |
(?=abc) | Positive lookahead |
Practical Patterns
Email Validation
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
URL Matching
https?:\/\/[\w.-]+(?:\.[a-zA-Z]{2,})(?:\/[\w./?%&=-]*)?
Password Strength
At least 8 characters, one uppercase, one lowercase, one digit, one special character:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$
For generating strong passwords, use our Password Generator.
Hex Color Codes
^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$
Convert between color formats with our Color Converter.
UUID Validation
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
Generate valid UUIDs with our UUID Generator.
Regex Performance Tips
- Be specific β
[a-zA-Z]is faster than. - Avoid catastrophic backtracking β Nested quantifiers like
(a+)+cause exponential time - Use non-capturing groups when you do not need the value
- Anchor your patterns β
^pattern$is faster than unanchored search - Test with edge cases β Use our Regex Tester before deploying
Frequently Asked Questions
What is the difference between * and +?
* matches zero or more occurrences, + requires at least one. So ab*c matches "ac" but ab+c does not.
How do I make regex case-insensitive?
Use the i flag: /pattern/i in JavaScript, re.IGNORECASE in Python.
Related Resources
- Regex for Email Validation β patterns that work in production
- Regex Tester Tool β test and debug patterns in real-time
- Password Generator β generate passwords matching regex rules
- UUID Generator β generate valid UUIDs