Skip to content
OnlineToolStudio

Common Regex Patterns

runs in your browserno sign-upfree

Tested regular expressions for email, URL, phone, IP address, dates, passwords, UUID, hex colours and more — with examples, notes, and one click to try them.

40 of 40 patterns · JavaScript syntax — every example below is tested, and the patterns also work in PHP (and Python, except \p{…}).

  • URL (http / https)

    Validate a value

    A web address starting with http:// or https://, with an optional port, path, query and fragment.

    /^https?:\/\/(?:[\w-]+\.)+[a-z]{2,}(?::\d{1,5})?(?:[\/?#]\S*)?$/i

    Matches

    • https://example.com
    • http://sub.example.co.uk:8080/path?q=1#top
    • https://www.example.org/a-b_c

    Doesn’t match

    • example.com
    • ftp://example.com
    • https://localhost
    • https://exa mple.com

    ⓘ Requires a dot in the host, so http://localhost is rejected — loosen it if you need local addresses.

    Open in Regex Tester
  • Find URLs in text

    Find in text

    Every http:// or https:// link inside a longer text.

    /https?:\/\/[^\s<>"']+/gi

    Finds a match in

    • Read https://example.com/docs today
    • Links: http://a.io and https://b.io

    No match in

    • No links here
    • www.example.com without a scheme

    ⓘ Punctuation right after a link (a full stop, a closing bracket) may be included — trim it if needed.

    Open in Regex Tester
  • Domain name

    Validate a value

    A domain such as example.com or mail.example.co.uk — labels of up to 63 characters, no leading or trailing hyphens.

    /^(?=.{1,253}$)(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+(?:[A-Za-z]{2,63}|xn--[A-Za-z0-9-]{1,59})$/

    Matches

    • example.com
    • mail.example.co.uk
    • my-site.io
    • xn--fsqu00a.xn--0zwm56d

    Doesn’t match

    • -example.com
    • example-.com
    • example
    • exa_mple.com
    • example.c
    Open in Regex Tester
  • IPv4 address

    Validate a value

    Four numbers from 0 to 255 separated by dots.

    /^(?:(?: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)$/

    Matches

    • 192.168.1.1
    • 8.8.8.8
    • 255.255.255.255
    • 0.0.0.0

    Doesn’t match

    • 256.1.1.1
    • 192.168.1
    • 192.168.01.1
    • 1.2.3.4.5
    Open in Regex Tester
  • IPv6 address

    Validate a value

    A full or shortened (::) IPv6 address.

    /^(?:(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?::[0-9a-fA-F]{1,4}){1,6}|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:))$/

    Matches

    • 2001:0db8:85a3:0000:0000:8a2e:0370:7334
    • 2001:db8::1
    • ::1
    • ::
    • fe80::

    Doesn’t match

    • 2001:db8::1::1
    • 12345::1
    • 2001:db8:85a3
    • g::1

    ⓘ Does not cover IPv4-mapped forms like ::ffff:192.0.2.1 or zone IDs (%eth0).

    Open in Regex Tester
  • MAC address

    Validate a value

    Six pairs of hex digits separated by colons or hyphens.

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

    Matches

    • 00:1A:2B:3C:4D:5E
    • 00-1a-2b-3c-4d-5e

    Doesn’t match

    • 00:1A:2B:3C:4D
    • 00:1A:2B:3C:4D:5G
    • 001A2B3C4D5E
    Open in Regex Tester
  • Finds the 11-character video ID ($1) in watch, embed, Shorts and youtu.be links.

    /(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{11})/

    Finds a match in

    • https://www.youtube.com/watch?v=dQw4w9WgXcQ
    • https://youtu.be/dQw4w9WgXcQ?t=10
    • https://www.youtube.com/shorts/abcdefghijk

    No match in

    • https://vimeo.com/12345
    • https://www.youtube.com/channel/xyz
    Open in Regex Tester
  • Email address (simple)

    Validate a value

    Something@something.something, with no spaces — the practical check most forms need.

    /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/

    Matches

    • name@example.com
    • first.last+tag@mail.example.co.uk
    • a@b.io

    Doesn’t match

    • name@example
    • name example@x.com
    • @example.com
    • name@.c

    ⓘ No regex can tell whether an address really exists — send a confirmation email for that.

    Open in Regex Tester
  • The exact rule browsers use for <input type="email">, from the HTML standard.

    /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

    Matches

    • name@example.com
    • o'neil@example.org
    • user@localhost

    Doesn’t match

    • name@-example.com
    • name@exa_mple.com
    • name@@example.com
    • na me@example.com

    ⓘ Like browsers, it accepts addresses without a dot in the domain (user@localhost).

    Open in Regex Tester
  • A plus sign, the country code and the number — 7 to 15 digits, no spaces. The format SMS and calling APIs expect.

    /^\+[1-9]\d{6,14}$/

    Matches

    • +14155552671
    • +442071838750
    • +919876543210

    Doesn’t match

    • 14155552671
    • +1 415 555 2671
    • +0123456789
    • +12345
    Open in Regex Tester
  • Digits with optional +, spaces, dots, hyphens and brackets — a loose check for what people type.

    /^\+?(?:\(?\d{1,4}\)?[\s.-]?){2,6}\d{2,4}$/

    Matches

    • +1 (415) 555-2671
    • 020 7183 8750
    • +91 98765 43210
    • 555.123.4567

    Doesn’t match

    • phone
    • 12
    • +1 (415) 555-abcd

    ⓘ Strip everything except digits and + before storing, then check the length for the country.

    Open in Regex Tester
  • Username

    Validate a value

    3 to 16 letters, digits or underscores.

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

    Matches

    • asha_rao
    • user123
    • JoDev

    Doesn’t match

    • ab
    • user name
    • user-name
    • a_very_long_username_here
    Open in Regex Tester
  • Strong password

    Validate a value

    At least 8 characters with a lower-case letter, an upper-case letter, a digit and a symbol.

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

    Matches

    • Passw0rd!
    • C0rrect-Horse
    • aB3$efgh

    Doesn’t match

    • password
    • Password1
    • PASSWORD1!
    • Ab1!

    ⓘ Length matters more than symbols — consider allowing long passphrases without these rules.

    Open in Regex Tester
  • @mentions

    Find in text

    Finds @username mentions ($1 is the name) but not email addresses.

    /(?<![\w@])@([A-Za-z0-9_]{1,30})/g

    Finds a match in

    • Thanks @asha and @jo_dev!

    No match in

    • write to name@example.com
    • no mentions
    Open in Regex Tester
  • #hashtags

    Find in text

    Finds hashtags in any language (#travel, #café, #नमस्ते).

    /#[\p{L}\p{N}_]+/gu

    Finds a match in

    • Loving it #travel #café
    • #नमस्ते दुनिया

    No match in

    • no tags here
    • just # alone

    ⓘ Python’s built-in re module has no \p{…} — use the regex package (pip install regex).

    Open in Regex Tester
  • Whole number

    Validate a value

    Digits with an optional minus sign.

    /^-?\d+$/

    Matches

    • 42
    • -7
    • 0

    Doesn’t match

    • 4.2
    • +-1
    • 1,000
    • (empty)
    Open in Regex Tester
  • Decimal number

    Validate a value

    A number with an optional sign and decimal part (dot as the decimal separator).

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

    Matches

    • 3.14
    • -0.5
    • +12
    • .75

    Doesn’t match

    • 3.
    • 1.2.3
    • 1,5
    • abc
    Open in Regex Tester
  • Numbers like 1,234,567.89 (commas every three digits, dot for decimals).

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

    Matches

    • 1,234
    • 1,234,567.89
    • 999

    Doesn’t match

    • 1234,567
    • 12,34
    • 1,234.
    Open in Regex Tester
  • Date (YYYY-MM-DD)

    Validate a value

    An ISO 8601 date such as 2026-11-12.

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

    Matches

    • 2026-11-12
    • 1999-01-31

    Doesn’t match

    • 2026-13-01
    • 2026-1-5
    • 12-11-2026
    • 2026-11-32

    ⓘ Checks the format, not the calendar: 2026-02-31 passes. Validate real dates in code.

    Open in Regex Tester
  • Date (DD/MM/YYYY)

    Validate a value

    Day first, as used in most of the world — with /, . or - between the parts.

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

    Matches

    • 12/11/2026
    • 31.12.1999
    • 01-01-2000

    Doesn’t match

    • 2026/11/12
    • 32/01/2026
    • 12/13/2026
    • 1/1/2026
    Open in Regex Tester
  • Date (MM/DD/YYYY)

    Validate a value

    Month first, as used in the United States.

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

    Matches

    • 11/12/2026
    • 12/31/1999

    Doesn’t match

    • 31/12/1999
    • 13/01/2026
    • 2026/11/12
    Open in Regex Tester
  • Time (24-hour)

    Validate a value

    HH:MM or HH:MM:SS from 00:00 to 23:59:59.

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

    Matches

    • 09:30
    • 23:59:59
    • 00:00

    Doesn’t match

    • 24:00
    • 9:30
    • 12:60
    • 12:30:60
    Open in Regex Tester
  • Times like 9:30 AM or 12:05pm.

    /^(?:0?[1-9]|1[0-2]):[0-5]\d\s?[AaPp][Mm]$/

    Matches

    • 9:30 AM
    • 12:05pm
    • 07:45 PM

    Doesn’t match

    • 13:00 PM
    • 9:30
    • 0:30 AM
    Open in Regex Tester
  • Date and time (ISO 8601)

    Validate a value

    Timestamps like 2026-11-12T09:30:00Z or 2026-11-12T09:30:00.123+05:30, as used in APIs.

    /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/

    Matches

    • 2026-11-12T09:30:00Z
    • 2026-11-12T09:30:00.123+05:30
    • 2026-11-12T09:30Z

    Doesn’t match

    • 2026-11-12 09:30:00
    • 2026-11-12T09:30:00
    • 2026-11-12
    Open in Regex Tester
  • Latitude, longitude

    Validate a value

    A coordinate pair like 51.5072, -0.1276 — latitude −90…90, longitude −180…180.

    /^[-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?),\s*[-+]?(?:180(?:\.0+)?|(?:1[0-7]\d|[1-9]?\d)(?:\.\d+)?)$/

    Matches

    • 51.5072, -0.1276
    • -33.8688,151.2093
    • 90, 180

    Doesn’t match

    • 91, 0
    • 0, 181
    • 51.5072
    Open in Regex Tester
  • Spaces at the start and end — replace with nothing to trim.

    /^\s+|\s+$/g

    Finds a match in

    • hello
    • tab

    No match in

    • hello
    Open in Regex Tester
  • Multiple spaces

    Find in text

    Two or more spaces in a row — replace with a single space.

    / {2,}/g

    Finds a match in

    • too many spaces

    No match in

    • one space each
    Open in Regex Tester
  • Blank lines

    Find in text

    Empty (or space-only) lines — replace with nothing to remove them.

    /^[ \t]*\r?\n/gm

    Finds a match in

    • line one line two
    • a b

    No match in

    • line one line two
    Open in Regex Tester
  • Repeated words

    Find in text

    A word typed twice in a row ("the the") — replace with $1 to fix.

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

    Finds a match in

    • This is the the end
    • It is is fine

    No match in

    • This is the end
    • theme the
    Open in Regex Tester
  • HTML tags

    Find in text

    Opening and closing tags like <p class="x"> and </p> — replace with nothing for a quick strip.

    /<\/?[a-zA-Z][^>]*>/g

    Finds a match in

    • <p>Hello <b>world</b></p>
    • <img src="a.png" />

    No match in

    • 5 < 6 and 7 > 3
    • plain text

    ⓘ Fine for quick clean-ups; for real HTML use a parser — or the Strip HTML Tags tool.

    Open in Regex Tester
  • Accented letters, emoji, curly quotes and other characters outside basic English ASCII.

    /[^\x00-\x7F]/g

    Finds a match in

    • café
    • it’s
    • hi 👋

    No match in

    • plain ASCII text
    Open in Regex Tester
  • Emoji

    Find in text

    Emoji characters — replace with nothing to remove them.

    /\p{Extended_Pictographic}/gu

    Finds a match in

    • Great job 🎉
    • Love ❤️ it

    No match in

    • No emoji here

    ⓘ Python’s built-in re module has no \p{…} — use the regex package (pip install regex).

    Open in Regex Tester
  • Hex colour

    Validate a value

    CSS hex colours: #rgb, #rgba, #rrggbb or #rrggbbaa.

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

    Matches

    • #fff
    • #1a2B3c
    • #ff000080
    • #abcd

    Doesn’t match

    • fff
    • #ff00f
    • #ggg
    • #1234567
    Open in Regex Tester
  • UUID

    Validate a value

    A UUID (versions 1–8) like 123e4567-e89b-42d3-a456-426614174000.

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

    Matches

    • 123e4567-e89b-42d3-a456-426614174000
    • 018F3C2A-7B1D-7C3E-9F00-123456789ABC

    Doesn’t match

    • 123e4567e89b42d3a456426614174000
    • 123e4567-e89b-02d3-a456-426614174000
    • not-a-uuid
    Open in Regex Tester
  • URL slug

    Validate a value

    Lower-case words joined by single hyphens, like my-blog-post-2026.

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

    Matches

    • my-blog-post
    • post-2026
    • a

    Doesn’t match

    • My-Post
    • my--post
    • -post
    • post-
    • my_post
    Open in Regex Tester
  • Semantic version

    Validate a value

    Versions like 1.4.2, 2.0.0-beta.1 or 1.0.0+build.5 — the official pattern from semver.org.

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

    Matches

    • 1.4.2
    • 2.0.0-beta.1
    • 1.0.0+build.5
    • 0.1.0

    Doesn’t match

    • 1.4
    • 01.2.3
    • v1.2.3
    • 1.2.3-
    Open in Regex Tester
  • JWT (JSON Web Token)

    Validate a value

    Three base64url parts separated by dots (the signature may be empty).

    /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/

    Matches

    • eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc-DEF_123
    • eyJhbGciOiJub25lIn0.eyJ4IjoxfQ.

    Doesn’t match

    • eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0
    • not a token
    • a.b.c.d
    Open in Regex Tester
  • Base64 text

    Validate a value

    Standard Base64 with correct padding (= or ==).

    /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/

    Matches

    • SGVsbG8=
    • SGVsbG8gV29ybGQ=
    • YWJj

    Doesn’t match

    • SGVsbG8
    • SGVsbG8===
    • SGV$bG8=
    Open in Regex Tester
  • File extension

    Find in text

    The extension at the end of a file name ($1 = "pdf" in report.final.pdf).

    /\.([A-Za-z0-9]+)$/

    Finds a match in

    • report.final.pdf
    • photo.JPEG

    No match in

    • README
    • folder/
    Open in Regex Tester
  • 16 digits, optionally in groups of four separated by spaces or hyphens.

    /^(?:\d{4}[ -]?){3}\d{4}$/

    Matches

    • 4111 1111 1111 1111
    • 4111-1111-1111-1111
    • 4111111111111111

    Doesn’t match

    • 4111 1111 1111
    • 4111 1111 1111 111a

    ⓘ Checks the shape only. Real card numbers also pass the Luhn check, and Amex has 15 digits.

    Open in Regex Tester

About this tool

A library of ready-to-use regular expressions for the things developers validate and search most: email addresses, URLs, domains, IPv4 and IPv6, phone numbers, usernames and passwords, dates and times, numbers, hex colours, UUIDs, slugs, versions, JWTs and text clean-up. Every pattern lists values it matches and values it rejects — all checked by automated tests — plus notes on its limits. “Open in Regex Tester” loads it with its examples so you can adapt it.

How to use

  1. Search for what you need, or filter by type.
  2. Copy the pattern, or read its examples and notes.
  3. Click “Open in Regex Tester” to try it on your own values and get code for your language.

FAQ

Which regex should I use to validate an email address?

For most forms, the simple pattern — something@something.something without spaces — is the right choice: it catches typos without rejecting real addresses. If you want exactly what browsers accept for <input type="email">, use the HTML5 pattern. Either way, only a confirmation email proves an address exists.

Do these patterns work in PHP, Python and Java?

They are written in JavaScript syntax and were also tested in PHP, where they behave the same. In Python they work too, except the ones using \p{…} (emoji, hashtags), which need the regex package. The Regex Tester converts any pattern into PHP, Python and Java code for you.

Why does the date pattern accept 31 February?

Regex checks the shape of text, not the calendar. Use the pattern to reject obviously wrong input, then check the real date in code (for example with your language’s date parsing).

Related tools

All tools