Free Regex Pattern Library

60+ ready-to-use regex patterns. Search, copy, and test inline.

About This Library

This is a curated, searchable collection of 60+ commonly-used regular expression patterns organized by category. Each pattern includes a description, the regex itself, and example matches. Click any pattern to copy it, or use the quick-test panel to validate text against it right on this page.

Everything runs in your browser · no patterns or test strings are sent anywhere. Use these patterns in JavaScript, Python, PHP, Java, Go, or any language that supports regular expressions. For more advanced testing with flags and capture groups, try our Regex Tester.

How It Works

  1. Browse or search: Browse patterns by category (validation, extraction, formatting) or search by name or use case.
  2. Preview the pattern: Each entry shows the regex, a description of what it matches, example inputs and matches, and caveats.
  3. Test with your data: Enter your own test string to verify the pattern matches what you expect.
  4. Copy to use: Copy the regex pattern in JavaScript, Python, or POSIX format for your codebase.

Why Use Regex Library?

Writing regular expressions from scratch is time-consuming and error-prone. Commonly-needed patterns for email validation, URL matching, phone number extraction, credit card detection, date parsing, and IP address validation have well-tested solutions, but finding a reliable one requires searching Stack Overflow, evaluating accuracy, and checking edge cases. This library compiles vetted patterns with documented edge cases, known limitations, and real-world test cases. It's faster than writing your own and more reliable than copying from random internet sources without testing.

Pattern Categories

Where regular expressions come from

The mathematical idea of a «regular set» was formalised by Stephen Cole Kleene in 1951 in the RAND research memorandum Representation of Events in Nerve Nets and Finite Automata. The * operator on this page is still called the Kleene star in his honour. Ken Thompson turned the theory into an algorithm in his June 1968 Communications of the ACM paper Programming Techniques: Regular Expression Search Algorithm, and shipped the first regex implementation in the QED editor at Bell Labs. By 1973 the same engine powered ed, then grep (the literal expansion is «globally search for regular expression and print»), sed, and awk. Larry Wall's Perl (1987) and especially Perl 5 (1994) added named groups, lookaround, non-greedy quantifiers and Unicode handling that became the de-facto dialect known as PCRE, ported to C as a library by Philip Hazel in 1997.

Engine flavors and what changes between them

A pattern that runs cleanly in JavaScript can silently fail in Go and outright reject in POSIX. The five flavors a developer is most likely to meet:

Catastrophic backtracking and ReDoS

Most regex engines in mainstream languages (PCRE, Java, JS V8 / SpiderMonkey / JavaScriptCore, Python re, .NET) are backtracking engines. When a pattern with nested quantifiers like (a+)+ hits an input that almost matches, the engine can try an exponential number of alternative paths before giving up. This is catastrophic backtracking, and it is the basis of the ReDoS (Regular expression Denial of Service) attack class catalogued by OWASP.

Stack Overflow, 20 July 2016: a pattern designed to trim leading and trailing whitespace, applied to a question body containing 20,000 consecutive whitespace characters, took 11 minutes of CPU per request and made the site unresponsive for 34 minutes. The post-mortem on the official Stack Status blog recommended replacing trim regexes with native string trim.

Cloudflare, 2 July 2019: a WAF rule containing the nested-quantifier pattern .*(?:.*=.*) was deployed globally and consumed 100% CPU on every edge server for 27 minutes, taking large portions of the public internet offline. Cloudflare's post-mortem on their blog credited the switch to Rust's regex crate (an RE2-based, linear-time engine) for preventing recurrence.

The defensive lessons: avoid nested quantifiers ((a+)+, (a*)*, (a|aa)+); avoid \s+$-style trims on attacker-controlled input; prefer atomic groups (?>...) or possessive quantifiers a++ in PCRE; and for high-throughput services consider an RE2-based engine.

Email, URL, phone, date, credit card: when not to use regex

Email. The full grammar of RFC 5322 (October 2008) compiles to a regex about 3,000 characters long. The W3C HTML5 specification for <input type="email"> validation uses a much shorter «is-this-plausibly-an-email» regex which is the right starting point for client-side hints. RFC 6531 (February 2012) permits non-ASCII addresses like 用户@example.com, which an ASCII-only regex will incorrectly reject. The industry consensus since RFC 6532: do not validate emails with regex, send a verification email instead.

URLs. RFC 3986 (January 2005) is the URI generic-syntax spec, but the WHATWG URL Living Standard deliberately diverges from it to match what browsers actually accept. Use new URL("...") in JavaScript or urllib.parse in Python rather than a regex for anything beyond a quick visual check.

Phone numbers. ITU-T Recommendation E.164 (current revision November 2010) allows up to 15 digits with an optional + prefix, but country-specific rules vary enormously. Google's open-source libphonenumber library encodes the per-country rules for every territory and is the only reliable cross-country validator.

Dates. A regex like ^\d{4}-\d{2}-\d{2}$ matches the ISO 8601-1:2019 calendar format, but it also accepts 2026-02-31. Date validity requires calendar logic, not pattern matching; use Date.parse() or a date library.

Credit cards. A regex can match the digit length and IIN prefix (Visa starts with 4, Mastercard with 51-55 or 2221-2720, Amex with 34 or 37) but cannot verify the Luhn checksum (Hans Peter Luhn, IBM, US Patent 2,950,048 granted August 1960). Luhn requires a digit-by-digit sum modulo 10.

Common ways developers use this library

Common mistakes

More frequently asked questions

Why do some patterns use (?:...) instead of (...)?

(?:...) is a non-capturing group: it groups for repetition or alternation but does not allocate a backreference slot. It is faster and avoids polluting $1, $2 in the result array. Use (...) when you need to extract the captured text; use (?:...) for grouping alone.

What are the most common regex flags?

i case-insensitive, g global (find all, JS-specific behaviour), m multiline (so ^ and $ match line boundaries), s dotAll (so . matches newlines, ES2018+), u Unicode (ES2015+), y sticky (ES2015+), d hasIndices (ES2022+), v set-notation classes (ES2024+). Combine as /pattern/gimsu.

How do I match a literal special character?

Escape it with a backslash. The regex metacharacters that need escaping when you want a literal match are: . ^ $ * + ? ( ) [ ] { } | \ /. Inside a character class [...] the set of special characters is smaller: only ] \ ^ - need escaping, depending on position.

Can I use this library's patterns in shell scripts?

Yes, with caveats. grep uses POSIX BRE by default; grep -E uses ERE; grep -P uses PCRE on systems where libpcre is linked (GNU grep, macOS grep with Homebrew). Patterns using lookaround, named groups, or Unicode property escapes need grep -P or ripgrep (which uses Rust's RE2-based engine and rejects lookaround).

Are these patterns sent to a server?

No. Every regex on this page, every search you type, and every string you test in the quick-test panel is processed in your browser's JavaScript engine. No network call is made. The pattern data itself is shipped as a static JSON file in the page bundle. Open the Network tab in DevTools to verify.

Related Tools