Skip to content
ToolMug

Common Regex Patterns

Ready-to-use regular expressions for everyday validation — email, URL, domain, IPv4 and MAC addresses, integers, decimals and money amounts, dates and times, usernames, strong passwords, hex colors, UUIDs and semantic versions, plus Chinese phone, ID and postcode formats. Each pattern comes with a description and matching and non-matching examples; copy it in one click or type into the box to test it.

Runs in your browser — nothing you enter is uploaded

  • Email address

    Common email format with dots, plus signs and multi-level domains

    /^[\w.+-]+@[\w-]+(\.[\w-]+)+$/

    ✓ name@example.com a.b+tag@mail.co.uk✗ name@ @example.com a b@example.com

  • URL (http/https)

    Starts with http:// or https:// and contains no spaces

    /^https?:\/\/[^\s/$.?#][^\s]*$/i

    ✓ https://example.com/path?q=1 http://localhost:8080✗ ftp://example.com example.com https:// bad

  • Domain name

    Multi-level domain of letters, digits and hyphens

    /^(?=.{1,253}$)(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$/

    ✓ example.com sub.example.co.uk✗ -bad.com example exa_mple.com

  • IPv4 address

    Four numbers from 0 to 255 without leading zeros

    /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/

    ✓ 192.168.1.1 8.8.8.8 255.255.255.0✗ 256.1.1.1 1.2.3 01.2.3.4

  • MAC address

    Six pairs of hex digits separated by colons or hyphens

    /^(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/

    ✓ 00:1A:2B:3C:4D:5E 00-1a-2b-3c-4d-5e✗ 001A2B3C4D5E 00:1A:2B:3C:4D

  • China mobile number

    11 digits starting with 13–19, without +86

    /^1[3-9]\d{9}$/

    ✓ 13800138000 19912345678✗ 12345678901 1380013800 +8613800138000

  • China landline

    Area code plus number, optionally separated by a hyphen

    /^0\d{2,3}-?\d{7,8}$/

    ✓ 010-12345678 0755-1234567 02112345678✗ 12345678 010-123

  • China ID card (18 digits)

    Checks the region code length and birth date; the last character may be X. The checksum is not verified.

    /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/

    ✓ 11010519491231002X 440308199901010012✗ 11010519491331002X 1101051949123100

  • China postcode

    Six digits

    /^\d{6}$/

    ✓ 100000 010000✗ 10000 1000000

  • China license plate

    7 characters for regular plates, 8 for new-energy vehicles

    /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/

    ✓ 京A12345 粤BD12345 沪A1234学✗ 京12345 京AI2345

  • Chinese characters only

    Common CJK ideographs only

    /^[\u4e00-\u9fa5]+$/

    ✓ 中文 正则表达式✗ 中文abc

  • QQ number

    5–11 digits, not starting with 0

    /^[1-9]\d{4,10}$/

    ✓ 10001 123456789✗ 01234 1234

  • Bank card number

    16–19 digits; validity also needs a Luhn check

    /^[1-9]\d{15,18}$/

    ✓ 6222021234567890123 4111111111111111✗ 0222021234567890 622202123456

  • Integer

    Optionally negative

    /^-?\d+$/

    ✓ 0 -42 12345✗ 1.5 1e3

  • Positive integer

    No leading zero

    /^[1-9]\d*$/

    ✓ 1 100✗ 0 01 -1

  • Decimal number

    Optionally negative, with digits on both sides of the point

    /^-?\d+(?:\.\d+)?$/

    ✓ 3.14 -0.5 42✗ .5 1. 1,000

  • Money amount

    Non-negative with up to two decimals

    /^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/

    ✓ 0 99.9 1234.56✗ 01.00 1.234 -1

  • Date (YYYY-MM-DD)

    Month 01–12 and day 01–31; month lengths are not checked

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

    ✓ 2026-09-26 1999-12-31✗ 2026-13-01 2026-9-26 26-09-2026

  • Time (HH:MM[:SS])

    24-hour clock, seconds optional

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

    ✓ 09:30 23:59:59✗ 24:00 9:30 12:60

  • Username

    Starts with a letter; 4–16 letters, digits or underscores

    /^[a-zA-Z][a-zA-Z0-9_]{3,15}$/

    ✓ alice_01 Bob2026✗ 1alice ab bad-name

  • Strong password

    At least 8 characters with upper and lower case letters, a digit and a symbol

    /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$/

    ✓ Passw0rd! Aa1@aaaa✗ password Password1 Aa1@

  • Hex color

    #RGB or #RRGGBB

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

    ✓ #fff #0F766E✗ fff #ffff #12345g

  • UUID

    Standard UUID format (versions 1–8)

    /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

    ✓ 123e4567-e89b-42d3-a456-426614174000✗ 123e4567-e89b-42d3-c456-426614174000 123e4567e89b42d3a456426614174000

  • Semantic version

    MAJOR.MINOR.PATCH with optional pre-release and build metadata

    /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/

    ✓ 1.0.0 2.1.3-beta.1+build.5✗ 1.0 01.0.0 v1.0.0

  • HTML tag pair

    Finds matching opening and closing tags, capturing the tag name and content

    /<([a-zA-Z][\w-]*)\b[^>]*>([\s\S]*?)<\/\1>/g

    ✓ <b>bold</b> <a href="#">link</a>✗ <b>unclosed plain text

  • Blank line

    With the m flag, finds empty or whitespace-only lines, e.g. to remove them

    /^\s*$/m

    ✓ ✗ text

Patterns use JavaScript syntax and work in most languages such as Java, Python and Go (mind the backslash escaping). They check format only; whether an ID or card number is real needs checksum or official validation.

How to use

  1. Search for a format or filter by category.
  2. Click Copy to take the pattern; escape backslashes when you put it in a string.
  3. Type into the box under a card to see instantly whether it matches.

Options explained

Syntax
Written for JavaScript and compatible with most languages such as Java, Python, Go and PHP; inside string literals, double the backslashes.
Whole-string matching
Validation patterns are anchored with ^ and $ so the entire input must match. To search in longer text, drop the anchors and add the g flag.
Format vs validity
A pattern checks format only. Whether an ID or card number is real needs a checksum or an official check.

How a pattern is built: the IPv4 example

The IPv4 pattern shows the usual structure of a validation regex. One octet is written as four alternatives, tried in order, so each accepts only 0–255:

25[0-5]      250–255
2[0-4]\d     200–249
1\d\d        100–199
[1-9]?\d     0–99, with no leading zero

The whole pattern is (octet\.){3}octet, anchored with ^ and $. That is why 192.168.1.1 matches while 256.1.1.1, 01.2.3.4 and 1.2.3 do not.

Format is not validity

A pattern checks shape only. The date pattern accepts 2026-02-30 because it allows day 30 in every month, and rejects 2026-13-01 because month 13 does not exist. For real dates, parse the value with your language’s date library after the regex check.

Frequently asked questions

Why isn’t the email regex fully RFC-compliant?

A fully RFC 5322-compliant regex is huge and rejects few real mistakes. Use a lenient check and confirm the address with a verification email.

How do I debug a more complex regex?

Use the regex tester, which highlights every match and group and can test replacements.

Do these patterns support Unicode?

Most target ASCII input. Add the u flag and Unicode property escapes such as \p{L} if you need to accept letters from any script.

Privacy

This tool runs entirely in your browser. Your files and text are processed on your device and are never uploaded to our servers.

Related tools