Common Regex Patterns Cheat Sheet

Tap a pattern to see the regex and what it validates.

Email Address

^[\w.-]+@[\w-]+\.[a-zA-Z]{2,}$ β€” validates a standard id@domain email address.

US Phone Number

^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ β€” validates a standard 10-digit US phone number, with or without area-code parentheses and separators.

URL

^https?://[\w.-]+\.[a-zA-Z]{2,}(/\S*)?$ β€” validates a web address starting with http:// or https://.

Strong Password

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$ β€” validates a password of at least 8 characters containing an uppercase letter, a lowercase letter, a digit, and a special character.

Date (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$ β€” validates a standard year-month-day date like 2026-01-15.

Hex Color Code

^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ β€” validates a 3- or 6-digit hex color code like #fff or #ffffff.

Digits Only

^\d+$ β€” checks whether a string consists of digits only.

Letters and Numbers Only

^[a-zA-Z0-9]+$ β€” checks whether a string contains only letters and numbers, with no special characters or spaces.

What Is a Regular Expression?

A regular expression (regex) is a pattern language used to find or validate strings that match a specific rule. It shows up everywhere from validating an email field on a signup form to cleaning messy data.

Want to Test a Pattern Yourself?

If you want to check whether a regex actually works the way you expect, a regex tester is worth trying as well.

Frequently Asked Questions

Do these patterns cover every possible case perfectly?

No β€” the patterns here are solid general-purpose starting points, and unusual edge cases may need further tuning.

Does regex syntax differ between programming languages?

Mostly not, but details like how escape characters are handled can vary slightly between languages and tools.