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 valueA web address starting with http:// or https://, with an optional port, path, query and fragment.
/^https?:\/\/(?:[\w-]+\.)+[a-z]{2,}(?::\d{1,5})?(?:[\/?#]\S*)?$/iMatches
- 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 TesterFind URLs in text
Find in textEvery http:// or https:// link inside a longer text.
/https?:\/\/[^\s<>"']+/giFinds 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 TesterDomain name
Validate a valueA 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})$/Open in Regex TesterMatches
- 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
IPv4 address
Validate a valueFour 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)$/Open in Regex TesterMatches
- 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
IPv6 address
Validate a valueA 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 TesterMAC address
Validate a valueSix pairs of hex digits separated by colons or hyphens.
/^(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/Open in Regex TesterMatches
- 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
YouTube video ID from a link
Find in textFinds the 11-character video ID ($1) in watch, embed, Shorts and youtu.be links.
/(?:youtube\.com\/(?:watch\?v=|embed\/|shorts\/)|youtu\.be\/)([\w-]{11})/Open in Regex TesterFinds 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
Email address (simple)
Validate a valueSomething@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 TesterEmail address (HTML5 standard)
Validate a valueThe 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 TesterPhone number (international E.164)
Validate a valueA 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}$/Open in Regex TesterMatches
- +14155552671
- +442071838750
- +919876543210
Doesn’t match
- 14155552671
- +1 415 555 2671
- +0123456789
- +12345
Phone number (any common format)
Validate a valueDigits 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 TesterUsername
Validate a value3 to 16 letters, digits or underscores.
/^[a-zA-Z0-9_]{3,16}$/Open in Regex TesterMatches
- asha_rao
- user123
- JoDev
Doesn’t match
- ab
- user name
- user-name
- a_very_long_username_here
Strong password
Validate a valueAt 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 textFinds @username mentions ($1 is the name) but not email addresses.
/(?<![\w@])@([A-Za-z0-9_]{1,30})/gOpen in Regex TesterFinds a match in
- Thanks @asha and @jo_dev!
No match in
- write to name@example.com
- no mentions
#hashtags
Find in textFinds hashtags in any language (#travel, #café, #नमस्ते).
/#[\p{L}\p{N}_]+/guFinds 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 TesterWhole number
Validate a valueDigits with an optional minus sign.
/^-?\d+$/Open in Regex TesterMatches
- 42
- -7
- 0
Doesn’t match
- 4.2
- +-1
- 1,000
- (empty)
Decimal number
Validate a valueA number with an optional sign and decimal part (dot as the decimal separator).
/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/Open in Regex TesterMatches
- 3.14
- -0.5
- +12
- .75
Doesn’t match
- 3.
- 1.2.3
- 1,5
- abc
Number with thousands separators
Validate a valueNumbers like 1,234,567.89 (commas every three digits, dot for decimals).
/^\d{1,3}(?:,\d{3})*(?:\.\d+)?$/Open in Regex TesterMatches
- 1,234
- 1,234,567.89
- 999
Doesn’t match
- 1234,567
- 12,34
- 1,234.
Date (YYYY-MM-DD)
Validate a valueAn 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 TesterDate (DD/MM/YYYY)
Validate a valueDay 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}$/Open in Regex TesterMatches
- 12/11/2026
- 31.12.1999
- 01-01-2000
Doesn’t match
- 2026/11/12
- 32/01/2026
- 12/13/2026
- 1/1/2026
Date (MM/DD/YYYY)
Validate a valueMonth first, as used in the United States.
/^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$/Open in Regex TesterMatches
- 11/12/2026
- 12/31/1999
Doesn’t match
- 31/12/1999
- 13/01/2026
- 2026/11/12
Time (24-hour)
Validate a valueHH:MM or HH:MM:SS from 00:00 to 23:59:59.
/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/Open in Regex TesterMatches
- 09:30
- 23:59:59
- 00:00
Doesn’t match
- 24:00
- 9:30
- 12:60
- 12:30:60
Time (12-hour with AM/PM)
Validate a valueTimes like 9:30 AM or 12:05pm.
/^(?:0?[1-9]|1[0-2]):[0-5]\d\s?[AaPp][Mm]$/Open in Regex TesterMatches
- 9:30 AM
- 12:05pm
- 07:45 PM
Doesn’t match
- 13:00 PM
- 9:30
- 0:30 AM
Date and time (ISO 8601)
Validate a valueTimestamps 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})$/Open in Regex TesterMatches
- 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
Latitude, longitude
Validate a valueA 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+)?)$/Open in Regex TesterMatches
- 51.5072, -0.1276
- -33.8688,151.2093
- 90, 180
Doesn’t match
- 91, 0
- 0, 181
- 51.5072
Leading and trailing spaces
Find in textSpaces at the start and end — replace with nothing to trim.
/^\s+|\s+$/gOpen in Regex TesterFinds a match in
- hello
- tab
No match in
- hello
Multiple spaces
Find in textTwo or more spaces in a row — replace with a single space.
/ {2,}/gOpen in Regex TesterFinds a match in
- too many spaces
No match in
- one space each
Blank lines
Find in textEmpty (or space-only) lines — replace with nothing to remove them.
/^[ \t]*\r?\n/gmOpen in Regex TesterFinds a match in
- line one line two
- a b
No match in
- line one line two
Repeated words
Find in textA word typed twice in a row ("the the") — replace with $1 to fix.
/\b(\w+)\s+\1\b/giOpen in Regex TesterFinds a match in
- This is the the end
- It is is fine
No match in
- This is the end
- theme the
Non-ASCII characters
Find in textAccented letters, emoji, curly quotes and other characters outside basic English ASCII.
/[^\x00-\x7F]/gOpen in Regex TesterFinds a match in
- café
- it’s
- hi 👋
No match in
- plain ASCII text
Emoji
Find in textEmoji characters — replace with nothing to remove them.
/\p{Extended_Pictographic}/guFinds 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 TesterHex colour
Validate a valueCSS hex colours: #rgb, #rgba, #rrggbb or #rrggbbaa.
/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/Open in Regex TesterMatches
- #fff
- #1a2B3c
- #ff000080
- #abcd
Doesn’t match
- fff
- #ff00f
- #ggg
- #1234567
UUID
Validate a valueA 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}$/iOpen in Regex TesterMatches
- 123e4567-e89b-42d3-a456-426614174000
- 018F3C2A-7B1D-7C3E-9F00-123456789ABC
Doesn’t match
- 123e4567e89b42d3a456426614174000
- 123e4567-e89b-02d3-a456-426614174000
- not-a-uuid
URL slug
Validate a valueLower-case words joined by single hyphens, like my-blog-post-2026.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Open in Regex TesterMatches
- my-blog-post
- post-2026
- a
Doesn’t match
- My-Post
- my--post
- -post
- post-
- my_post
Semantic version
Validate a valueVersions 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-]+)*))?$/Open in Regex TesterMatches
- 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-
JWT (JSON Web Token)
Validate a valueThree base64url parts separated by dots (the signature may be empty).
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/Open in Regex TesterMatches
- eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc-DEF_123
- eyJhbGciOiJub25lIn0.eyJ4IjoxfQ.
Doesn’t match
- eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0
- not a token
- a.b.c.d
Base64 text
Validate a valueStandard Base64 with correct padding (= or ==).
/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/Open in Regex TesterMatches
- SGVsbG8=
- SGVsbG8gV29ybGQ=
- YWJj
Doesn’t match
- SGVsbG8
- SGVsbG8===
- SGV$bG8=
File extension
Find in textThe extension at the end of a file name ($1 = "pdf" in report.final.pdf).
/\.([A-Za-z0-9]+)$/Open in Regex TesterFinds a match in
- report.final.pdf
- photo.JPEG
No match in
- README
- folder/
Card number format (16 digits)
Validate a value16 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
- Search for what you need, or filter by type.
- Copy the pattern, or read its examples and notes.
- 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).