Regex Playground

Build, test, and understand regular expressions visually

/
/g

Quick Reference

.Any character
\dDigit
\wWord char
\sWhitespace
^Start
$End
*0 or more
+1 or more
?Optional
[abc]Character set
(ab)Group
|Or

Pattern Library

Email (Simple)

Email

Basic email validation pattern

/^[^\s@]+@[^\s@]+\.[^\s@]+$/
Example:
[email protected]test.name+tag@domain...
#email#validation#simple

Email (RFC 5322)

Email

Comprehensive RFC 5322 compliant email pattern

/^[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])?)*$/
#email#validation#rfc

HTTP/HTTPS URL

URL

Matches HTTP and HTTPS URLs

/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/
Example:
https://example.comhttp://www.test.com/...
#url#http#web

Any URL

URL

Matches any URL including ftp, file, etc.

/^(?:[a-z][a-z0-9+.-]*:)?\/\/(?:(?:[a-z0-9-._~%!$&'()*+,;=]+|\[[a-f0-9:.]+\])@)?(?:[a-z0-9-._~%!$&'()*+,;=]+|\[[a-f0-9:.]+\])(?::[0-9]+)?(?:\/[a-z0-9-._~%!$&'()*+,;=:@]*)*(?:\?[a-z0-9-._~%!$&'()*+,;=:@\/?]*)?(?:#[a-z0-9-._~%!$&'()*+,;=:@\/?]*)?$/
Example:
ftp://files.example....https://sub.domain.c...
#url#protocol#web

UUID v4

UUID

Matches UUID version 4 format

/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/
Example:
550e8400-e29b-41d4-a...6ba7b810-9dad-11d1-8...
#uuid#guid#identifier

UUID (Any Version)

UUID

Matches any UUID version

/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/
Example:
550e8400-e29b-41d4-a...6ba7b810-9dad-11d1-8...
#uuid#guid#identifier

Phone (International)

Phone

International phone number with country code

/^\+(?:[0-9] ?){6,14}[0-9]$/
Example:
+1 555 123 4567+44 20 7123 4567
#phone#international#mobile

Phone (US)

Phone

US phone number in various formats

/^(?:\+?1[-.\s]?)?\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})$/
Example:
(555) 123-4567555-123-4567
#phone#us#north-america

Date (ISO 8601)

Date

ISO 8601 date format (YYYY-MM-DD)

/^([0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/
Example:
2024-01-151999-12-31
#date#iso#format

Date (US Format)

Date

US date format (MM/DD/YYYY)

/^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/([0-9]{4})$/
Example:
01/15/202412/31/1999
#date#us#format

Date (EU Format)

Date

European date format (DD/MM/YYYY)

/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[0-2])\/([0-9]{4})$/
Example:
15/01/202431/12/1999
#date#european#format

Time (24-hour)

Time

24-hour time format (HH:MM)

/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/
Example:
14:3023:59
#time#24-hour#format

Time (12-hour)

Time

12-hour time with AM/PM

/^(0?[1-9]|1[0-2]):[0-5][0-9]\s?(?:[AP]M|[ap]m)?$/
Example:
2:30 PM11:59am
#time#12-hour#am-pm

Integer

Number

Positive and negative integers

/^-?[0-9]+$/
Example:
-420
#number#integer#whole

Decimal Number

Number

Numbers with optional decimal places

/^-?[0-9]+(?:\.[0-9]+)?$/
Example:
-3.140
#number#decimal#float

Percentage

Number

Percentage value (0-100)

/^(?:100|[1-9]?[0-9])%?$/
Example:
50%100
#number#percentage#percent

URL Slug

Text

URL-friendly slug (lowercase, hyphens)

/^[a-z0-9]+(?:-[a-z0-9]+)*$/
Example:
my-blog-postproduct-123
#slug#url#seo

Username

Text

Alphanumeric username with underscores

/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/
Example:
john_doeUser123
#username#user#account

Hashtag

Text

Social media hashtag

/^#[a-zA-Z0-9_]+$/
Example:
#trending#HelloWorld
#hashtag#social#twitter

Strong Password

Validation

At least 8 chars, uppercase, lowercase, number, special char

/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/
Example:
P@ssw0rd!Str0ng#Pass
#password#security#strong

US Zip Code

Validation

US ZIP code (5 digits or ZIP+4)

/^[0-9]{5}(?:-[0-9]{4})?$/
Example:
1234590210-1234
#postal#zip#us

UK Postcode

Validation

UK postcode format

/^[A-Z]{1,2}[0-9][A-Z0-9]? ?[0-9][A-Z]{2}$/
Example:
SW1A 1AAM1 1AA
#postal#postcode#uk

IPv4 Address

Web

IPv4 address format

/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
Example:
192.168.1.1127.0.0.1
#ip#ipv4#network

Domain Name

Web

Valid domain name without protocol

/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/
Example:
example.comsub.domain.co.uk
#domain#dns#web

HTML Tag

Web

Matches HTML tags (opening or closing)

/<\/?[a-z][\s\S]*?>/
Example:
<div></span>
#html#tag#markup

JSON String

Data

Quoted JSON string with escape sequences

/^"(?:[^"\\]|\\.)*"$/
Example:
"hello""line\nbreak"
#json#string#data

Base64 String

Data

Base64 encoded string

/^[A-Za-z0-9+\/]+=*$/
Example:
SGVsbG8gV29ybGQ=YWJjMTIz
#base64#encoding#data

Hex Color

Data

Hexadecimal color code (3, 6, or 8 digits)

/^#(?:[0-9a-fA-F]{3}){1,2}$|^#(?:[0-9a-fA-F]{4}){1,2}$/
Example:
#fff#FF5733
#color#hex#css

Credit Card Number

Security

Common credit card number formats

/^(?:[0-9]{4}[-\s]?){3}[0-9]{4}$/
Example:
1234-5678-9012-34564111 1111 1111 1111
#credit-card#payment#finance

JWT Token

Security

JSON Web Token format

/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/
Example:
eyJhbGciOiJIUzI1NiIs...
#jwt#token#auth

API Key (Generic)

Security

Common API key formats (32-64 hex chars)

/^[a-fA-F0-9]{32,64}$/
Example:
a1b2c3d4e5f6a1b2c3d4...1234567890abcdef1234...
#api-key#key#secret