Developer tools

Regex Library

Regex Library: Common Patterns

Ready-made, tested regex patterns for emails, URLs, IPs, dates, phone numbers, Indian PAN, GSTIN, PIN and more, with code for five languages.

About this tool

About Regex Library

A searchable collection of regular expressions for the values developers validate every day, each one tested against real examples before it was added. You will find practical patterns for email addresses, URLs, domains, IPv4 and IPv6 addresses, CIDR blocks, MAC addresses, ISO dates, day-first and month-first dates, 12 and 24-hour times, E.164 and US phone numbers, ZIP codes, UK and Canadian postcodes, card number shapes, IBANs, UUIDs, semantic versions and more. There is a dedicated India section with PAN, GSTIN, Aadhaar shape, IFSC, PIN code, mobile number and vehicle registration patterns. Every entry explains what it accepts, shows examples it matches and rejects, and is honest about limits: a regex can't check a Luhn or GST checksum or whether 31 April exists, and the notes say so. Copy the pattern on its own or as ready code for a JavaScript literal, new RegExp, Python, PHP or Java, with named groups and flags converted. Then type your own values into the built-in tester to check them line by line.

Built and maintained by Abhi JainUpdated

How to Use a Regex Pattern

  1. 1

    Find a pattern

    Type in the search box (for example email, PAN or date) or pick a category such as India or Network.

  2. 2

    Read the examples

    Open a pattern to see what it matches, what it rejects, and any limits in the note.

  3. 3

    Try your own values

    Type values into Try it, one per line; each line is marked as matching or not.

  4. 4

    Copy the code

    Choose JS literal, new RegExp, Python, PHP or Java, then click Copy code or Copy pattern.

Regex Library: questions and answers

What is the best regex for validating an email address?

There is no perfect one. The full RFC 5322 grammar allows quoted local parts and IP-literal domains that real sign-up forms reject, so most apps use a practical pattern like the one here: letters, digits and . _ % + - before the @, no leading or double dots, and a domain with a TLD of at least two letters. The only real proof an address works is a confirmation email.

What is the regex for an Indian PAN number?

^[A-Z]{3}[ABCFGHLJPT][A-Z]\d{4}[A-Z]$. That is three letters, a fourth letter for the holder type (P for a person, C for a company and so on), a fifth letter, four digits and a final letter, for example ABCPE1234F.

Can a regex validate a credit card or GST number completely?

No. A regex can check the shape (prefix, length, character types), but card numbers use the Luhn checksum and GSTINs end with a check character that need real arithmetic. Use the regex as a first filter, then verify the checksum in code.

Will these patterns work in Python, PHP or Java?

Mostly yes. Use the language buttons to get converted code: named groups become (?P<name>…) for Python, flags become re.IGNORECASE or Pattern.CASE_INSENSITIVE, and PHP gets delimiters. Python's built-in re module has no \p{…} classes, which the tool points out when a pattern uses them.

Why does a date regex accept 2023-02-31?

Regular expressions match characters, not calendars, so they can't know month lengths or leap years without becoming unreadable. Check the format with the regex, then confirm the date is real with your language's date functions.