Regex Templates

A library of common JavaScript RegExp patterns — contact, network, identity, web, datetime, security, and more.

All processing on this page runs locally in your browser unless noted otherwise.

34 templates

CN mobile phone

Contact
/1[3-9]\d{9}/g

Call 13812345678 or 15900001111 today.

International phone

Contact
/\+?[1-9]\d{7,14}/g

+8613812345678 / +12025550123 / 442071838750

Username

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

alice_01 _bad ab ValidUser

URL

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

Visit https://example.com/path and http://localhost:3000/regex

IPv4

Network
/(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)/g

Servers: 192.168.1.1, 10.0.0.42, 8.8.8.8, 999.1.1.1

IPv6

Network
/(?:[A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}/gi

Addr: 2001:0db8:85a3:0000:0000:8a2e:0370:7334

MAC address

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

NIC 00:1A:2B:3C:4D:5E or 00-1A-2B-3C-4D-5E

Domain name

Network
/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}/gi

Hosts: example.com, sub.toolsworkbox.com, localhost

CN ID card

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

ID sample: 11010519491231002X

UUID

Identity
/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}/gi

id=550e8400-e29b-41d4-a716-446655440000

Hex color

Identity
/#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g

colors: #fff #1a2b3c #11223344 #gg0000

URL slug

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

hello-world Hello hello--world post-2024

Chinese characters

Text
/[\u4e00-\u9fff]+/g

Hello 世界 and 正则工具箱

Number

Text
/-?\d+(?:\.\d+)?/g

Values: 42, -3.14, 1000, .5

Integer

Text
/-?\d+/g

ints 1 -2 003 4.5

Blank line

Text
/^\s+$/gm

ok end

Quoted string

Text
/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g

say "hello\"world" and 'it\'s fine'

HTML tag

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

<div class="x">hi</div><br/>

Markdown link

Web
/\[([^\]]+)\]\(([^)]+)\)/g

See [docs](https://example.com) and [home](/).

CSS class

Web
/\.[a-zA-Z_-][\w-]*/g

div.btn .is-active #id .2bad

Query parameter

Web
/[?&]([^=&#]+)=([^&#]*)/g

https://x.com/?q=regex&lang=zh&empty=

ISO date

Date & time
/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g

dates 2024-01-15 2024-13-01 1999-12-31

CN date

Date & time
/\d{4}年(?:0?[1-9]|1[0-2])月(?:0?[1-9]|[12]\d|3[01])日/g

会议 2024年3月5日 / 2024年12月31日

24h time

Date & time
/(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?/g

log 09:30 23:59:01 24:00 7:5

ISO datetime

Date & time
/\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?/g

2024-01-15T10:22:01Z 2024-01-15 10:22:01+08:00

Strong password

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

Abcd1234! weak NoSpecial1

JWT token

Security
/eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g

token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.abc

Base64

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

payload SGVsbG8gV29ybGQ= end

Credit card digits

Security
/\b(?:\d[ -]*?){13,19}\b/g

card 4111 1111 1111 1111 / 5500-0000-0000-0004

JS identifier

Code
/[$A-Za-z_][$\w]*/g

const fooBar = $el; 12bad

SemVer

Code
/\b\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?\b/g

v1.2.3 2.0.0-beta.1 1.0.0+build.7

Git commit hash

Code
/\b[0-9a-f]{7,40}\b/gi

commit a1b2c3d and full deadbeefdeadbeefdeadbeefdeadbeefdeadbeef

Email header line

Code
/^[A-Za-z0-9-]+:\s*.+$/gm

From: [email protected] Subject: Hello body

How to use

  1. Filter by category or search by name / pattern.
  2. Click “Use + sample” to open the tester with pattern, flags, and sample text.
  3. All patterns target the JavaScript RegExp engine used by this site.

FAQ

Are these patterns production-ready?

They are practical starting points. Always test against your real data and locale rules.

Can I add my own templates?

Use Favorites on the tester page, or export/import JSON from the Import / Export tab.

Related tools