Advertisement

Regex Pattern Library

Browse and copy common regex patterns for emails, URLs, dates, IPs, and more.

//

Pattern Library

Email Address

Matches standard email addresses

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

URL (HTTP/HTTPS)

Matches HTTP and HTTPS URLs

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

US Phone Number

Matches US phone numbers in various formats

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

IPv4 Address

Matches valid IPv4 addresses (0.0.0.0 - 255.255.255.255)

(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)

IPv6 Address

Matches full IPv6 addresses

(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}

Date (YYYY-MM-DD)

Matches dates in ISO format

\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])

Date (MM/DD/YYYY)

Matches dates in US format

(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}

Time (HH:MM:SS)

Matches 24-hour time format

(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d

Hex Color Code

Matches 3 or 6 digit hex color codes

#(?:[0-9a-fA-F]{3}){1,2}

HTML Tag

Matches opening and closing HTML tags

<([a-zA-Z][a-zA-Z0-9]*)\b[^>]*>(?:.*?)<\/\1>

Credit Card Number

Matches Visa, MasterCard, Discover, and Amex formats

(?:4\d{3}|5[1-5]\d{2}|6011|3[47]\d{2})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}

US ZIP Code

Matches 5-digit and ZIP+4 formats

\d{5}(?:-\d{4})?

Username

3-16 chars: letters, numbers, underscore, hyphen

^[a-zA-Z0-9_-]{3,16}$

Strong Password

Min 8 chars with upper, lower, digit, and special char

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

File Extension

Matches file extensions

\.([a-zA-Z0-9]{1,10})$

CSS Property

Matches CSS property declarations

[a-z-]+\s*:\s*[^;]+;

Whitespace Trimming

Matches leading and trailing whitespace

^\s+|\s+$

Duplicate Words

Finds consecutive duplicate words

\b(\w+)\s+\1\b

Number with Commas

Matches formatted numbers like 1,234,567.89

\d{1,3}(?:,\d{3})*(?:\.\d+)?

Slug (URL-friendly)

Matches URL-friendly slugs

^[a-z0-9]+(?:-[a-z0-9]+)*$

Select a pattern or enter your own regex

Browse the pattern library below to get started

Advertisement

Related Tools

Advertisement

Frequently Asked Questions

What is a regex generator?
A regex generator helps you create regular expressions by providing a library of pre-built, tested patterns for common use cases like email validation, URL matching, phone number formats, IP addresses, and dates. Instead of writing complex regex from scratch, you can start with a proven pattern and customize it.
What common regex patterns are included?
The library includes patterns for email addresses, URLs (HTTP/HTTPS), phone numbers (US and international), IPv4 and IPv6 addresses, dates in various formats, credit card numbers, postal codes, hex color codes, usernames, strong passwords, HTML tags, and file extensions.
Can I test regex patterns against my own text?
Yes, there is a test area where you can paste sample text and see which parts match your regex pattern in real-time. Matches are highlighted so you can visually verify that the pattern captures exactly what you intend.
What regex flags are supported?
The tool supports all standard JavaScript regex flags: g (global), i (case-insensitive), m (multiline), s (dotAll), and u (unicode). You can toggle these flags on and off to modify how your pattern matches text.
How do I copy a regex pattern?
Click the copy button next to any pattern in the library to copy it to your clipboard. The pattern is copied as a plain string that you can use directly in your code. You can also copy the full regex literal including flags.
Is this tool suitable for production regex?
The patterns provided are well-tested starting points for common validation scenarios. However, for production use, you should always test patterns thoroughly against your specific data and edge cases. Some patterns like email validation have inherent complexity that no single regex can fully capture according to RFC specifications.

How to Use the Regex Generator

Regular expressions are one of the most powerful tools in a developer's toolkit, but writing them from scratch can be time-consuming and error-prone. Our Regex Generator provides a curated library of tested patterns for the most common validation and matching tasks, along with a real-time tester to verify your patterns against sample data.

Step 1: Browse the pattern library. Explore our collection of common regex patterns organized by category. Each pattern comes with a description explaining what it matches and common use cases. Click any pattern to load it into the tester.

Step 2: Test against your data. Paste sample text into the test area and see real-time match highlighting. The tool shows all matches in your text, helping you verify that the pattern works correctly for your specific data format and edge cases.

Step 3: Copy and use. Once you are satisfied with the pattern, click the copy button to copy it to your clipboard. Use it directly in your JavaScript, Python, PHP, or any language that supports regular expressions.

Understanding Regular Expressions

Regular expressions (regex) are sequences of characters that define search patterns. They are used in virtually every programming language for string matching, validation, search and replace operations, and data extraction. While the syntax can seem cryptic at first, regex follows logical rules that become intuitive with practice.

The basic building blocks of regex include literal characters, character classes (like \d for digits and \w for word characters), quantifiers (like + for one or more and * for zero or more), anchors (^ for start and $ for end of string), and groups (parentheses for capturing matched text). Combining these elements lets you describe complex text patterns concisely.

JavaScript, the language running in your browser, uses the RegExp object for regex operations. The test() method checks if a pattern matches a string, the match() method returns match details, and String methods like replace() and split() accept regex patterns. Understanding these methods is essential for effective text processing in web development.

Common Regex Pattern Use Cases

Form validation. The most common use of regex in web development is validating user input in forms. Email addresses, phone numbers, postal codes, and passwords all have specific format requirements that regex can enforce. Client-side validation provides instant feedback to users before form submission.

Data extraction. When processing text data, regex helps you extract specific information like dates, amounts, identifiers, or structured data from unstructured text. This is essential for log parsing, data cleaning, web scraping, and ETL processes.

Search and replace. Text editors and IDEs use regex for powerful search and replace operations. You can find all occurrences of a pattern and replace them with transformed text, including captured groups from the original match. This is invaluable for code refactoring and bulk text transformations.

URL routing. Web frameworks use regex patterns to define URL routes and extract parameters. Express.js, Django, Ruby on Rails, and many other frameworks rely on regex-based routing to map incoming requests to the correct handler functions.

Advertisement