alltools.one
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

PatternMatchesExample
.Any character except newlinea.c matches "abc", "a1c"
\dAny digit (0-9)\d{3} matches "123"
\wWord character (letter, digit, underscore)\w+ matches "hello_1"
\sWhitespace\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

PatternMeaning
*Zero or more
+One or more
?Zero or one
{n}Exactly n times
{n,m}Between n and m times

Anchors and Groups

PatternMeaning
^Start of string
$End of string
\bWord boundary
(abc)Capturing group
(?:abc)Non-capturing group
a|bAlternation (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

  1. Be specific β€” [a-zA-Z] is faster than .
  2. Avoid catastrophic backtracking β€” Nested quantifiers like (a+)+ cause exponential time
  3. Use non-capturing groups when you do not need the value
  4. Anchor your patterns β€” ^pattern$ is faster than unanchored search
  5. 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

Published on 2026-02-19
Regex Cheat Sheet: Patterns Every Developer Needs | alltools.one