DollarWise

30 Regex Patterns Every Developer Should Save

October 20, 2026 · 4 min read · By the DollarWise team
30 Regex Patterns Every Developer Should Save

Regular expressions are the fastest way to validate input, parse text, and clean up data, but nobody memorizes thirty patterns. This pack collects the thirty regex patterns developers actually reach for: email, URL, phone number, date, IPv4 address, hex color, slug, strong password, and more. Each pattern comes with a plain-English explanation of what it matches and where to use it. Bookmark this page or grab the free download, and you will never write an email validator from scratch again.

What’s inside this pack

The thirty patterns cover validation, extraction, and cleanup. Validation patterns check emails, URLs, phone numbers, dates, times, IP addresses, UUIDs, and passwords before bad data enters your system. Extraction patterns pull links, hashtags, and file extensions out of messy text. Cleanup patterns strip HTML tags, trim whitespace, and catch duplicate words. Every pattern includes a short explanation in plain language, plus notes on the common gotchas, like why the email pattern is practical rather than RFC-perfect, and where the IPv4 pattern needs an extra range check. Copy any pattern straight into JavaScript, Python, or any regex flavor.

8 essential regex patterns (free sample)

Here are eight of the most-used patterns, each shown as a code block with a plain-English explanation underneath. The patterns are written in a widely compatible style that works in JavaScript, Python, and most other languages. Test each pattern against your own edge cases before shipping it: regex is powerful, but a pattern that works for ninety-nine inputs can still surprise you on the hundredth. The free download contains all thirty patterns with explanations and usage notes.

  1. Validate an email address:
/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Matches a practical email format: some text, an @ sign, more text, a dot, and a domain. It rejects spaces and missing @ signs, which covers nearly every real-world mistake.

  1. Match a URL:
/https?:\/\/[^\s/$.?#].[^\s]*/

Matches http and https URLs in text. Useful for auto-linking URLs in comments, chat messages, and user bios.

  1. International phone number:
/^\+?[1-9]\d{7,14}$/

Matches phone numbers with an optional leading plus, following the international E.164 digit range. Adjust the length limits if your app only serves one country.

  1. Date in YYYY-MM-DD format:
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/

Matches ISO-style dates and rejects impossible months and days like month 13 or day 00. Note it still allows February 31, so pair it with a real date parser for strict validation.

  1. IPv4 address:
/^(?:\d{1,3}\.){3}\d{1,3}$/

Matches the four-group dotted shape of an IPv4 address. It does not check that each group is 255 or below, so add a numeric range check when that matters.

  1. Hex color code:
/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/

Matches CSS-style hex colors like #fff and #1a2b3c. Handy for validating color inputs in theme pickers and design tools.

Advertisement
  1. URL slug:
/^[a-z0-9]+(?:-[a-z0-9]+)*$/

Matches clean lowercase slugs like my-blog-post. No leading or trailing dashes, no double dashes, no uppercase.

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

Requires at least 8 characters with one lowercase letter, one uppercase letter, one digit, and one special character. The lookaheads check each rule without consuming characters.

How to use this pack

  1. Find the pattern that matches your task in the list below.
  2. Copy the pattern without the surrounding slashes if your language does not use them.
  3. Test it against valid and invalid examples before using it in production.
  4. Adjust for your locale: phone, postal code, and date patterns vary by country.
  5. For security-sensitive checks like passwords, pair regex with server-side logic.
  6. Save the download somewhere you can search it, like a snippets file.

Regex rewards testing and punishes assumptions. A pattern copied from a cheat sheet is a starting point, not a guarantee, so run it against your real data, including the weird edge cases, before it goes anywhere near production.

Frequently asked questions

Why not use one perfect email regex?

A truly RFC-compliant email pattern is thousands of characters long and unreadable. The practical pattern in this pack catches real-world mistakes like missing @ signs and spaces, which covers nearly every case that matters in an app.

Do these patterns work in Python too?

Yes. The patterns use standard syntax shared by JavaScript, Python, PHP, Java, and most other languages. Just drop the / delimiters and pass the pattern to your language’s regex functions.

Download the full pack

Advertisement
Written by the DollarWise team

We turn confusing money topics into plain-English guides for beginners. Every article is written to be actionable on day one — no jargon, no hype, no sales pitch.