Article

Regex Patterns Cheat Sheet: The Most Useful Regular Expressions

A practical regex cheat sheet with ready-to-use patterns for emails, URLs, phone numbers, dates, and IP addresses, with explanations and examples.

January 23, 2026by Useful Tools TeamDeveloper Guides

Regular expressions are one of the most powerful tools in a developer's toolkit, but they can also be intimidating. This cheat sheet covers the most common regex patterns you will actually use in real projects.

Basic Character Classes

Before diving into full patterns, here are the building blocks:

  • . — Matches any single character except newline
  • \d — Any digit (0-9)
  • \w — Any word character (letters, digits, underscore)
  • \s — Any whitespace (space, tab, newline)
  • [abc] — Any character in the set
  • [^abc] — Any character NOT in the set

Quantifiers

  • * — Zero or more
  • + — One or more
  • ? — Zero or one (optional)
  • {3} — Exactly 3 times
  • {2,5} — Between 2 and 5 times

Email Validation

A practical email regex that handles most real-world addresses:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

This matches standard email formats like [email protected] and [email protected]. It requires at least one character before the @, a domain name, and a top-level domain of at least two characters.

URL Matching

To match HTTP and HTTPS URLs:

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

Simpler Alternative

If you just need basic URL detection:

https?:\/\/[^\s]+

Phone Numbers

For US phone numbers in various formats:

^(\+1)?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$

This matches formats like (555) 123-4567, 555.123.4567, and +1-555-123-4567.

Date Formats

DD/MM/YYYY or MM/DD/YYYY

^\d{2}[\/\-]\d{2}[\/\-]\d{4}$

ISO 8601 (YYYY-MM-DD)

^\d{4}-\d{2}-\d{2}$

IP Addresses

IPv4

^(\d{1,3}\.){3}\d{1,3}$

For stricter validation (0-255 per octet), you need a more complex pattern, but this handles most use cases.

Password Validation

Require at least 8 characters, one uppercase, one lowercase, one digit, and one special character:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Common Text Patterns

Remove HTML Tags

<[^>]*>

Extract Hashtags

#[a-zA-Z0-9_]+

Match Hex Color Codes

#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})

Tips for Writing Better Regex

  • Start simple and add complexity as needed
  • Test incrementally — add one condition at a time
  • Use non-capturing groups (?:...) when you do not need the match
  • Be specific rather than using broad wildcards
  • Comment complex patterns for your future self

Test Your Patterns

Writing regex without testing is a recipe for bugs. Use our Regex Tester to validate your patterns against sample text in real time. It highlights matches, shows capture groups, and helps you debug issues quickly.

Regular expressions take practice, but with these common patterns as a starting point, you can handle the vast majority of text-matching tasks you will encounter in web development.

Disclosure: We may earn affiliate commissions from some of the products and services recommended on this site. This does not affect the price you pay and helps support our service to provide free tools.

Related Articles

More articles coming soon for: regex cheat sheet, regular expressions, regex patterns, regex examples, regex reference