Tài liệu tham khảo Regex có thể tìm kiếm và in được — lớp ký tự, anchor, quantifier, group, lookaround, flag và các mẫu có sẵn. Miễn phí.

Character classes

12
\d
Any digit, equivalent to [0-9]
\D
Any non-digit character
\w
Word character: letter, digit or underscore
\W
Any non-word character
\s
Any whitespace (space, tab, newline)
\S
Any non-whitespace character
.
Any character except newline
[abc]
Any one of a, b or c
[^abc]
Any character except a, b or c
[a-z]
Any lowercase letter in the range
[A-Za-z0-9]
Any alphanumeric character
[\d\s]
Combine classes inside brackets

Anchors & boundaries

8
^
Start of string (or line in multiline mode)
$
End of string (or line in multiline mode)
\b
Word boundary between \w and \W
\B
Not a word boundary
\A
Start of the entire string (PCRE)
\z
End of the entire string (PCRE)
\Z
End of string, before a trailing newline (PCRE)
\G
Start of the current match attempt (PCRE)

Quantifiers

11
*
Zero or more of the preceding token
+
One or more of the preceding token
?
Zero or one (makes it optional)
{n}
Exactly n repetitions
{n,}
n or more repetitions
{n,m}
Between n and m repetitions
*?
Lazy: zero or more, as few as possible
+?
Lazy: one or more, as few as possible
??
Lazy: optional, prefers zero
{2,5}?
Lazy bounded repetition
a++
Possessive: no backtracking (PCRE)

Groups & backreferences

9
(abc)
Capturing group, stores the match
(?:abc)
Non-capturing group
(?<name>abc)
Named capturing group
(?P<name>abc)
Named group, alternate PCRE syntax
a|b
Alternation: match a or b
(red|blue)
Grouped alternation
\1
Backreference to capturing group 1
\k<name>
Backreference to a named group
$1
Reference group 1 in a replacement

Lookaround

6
(?=abc)
Positive lookahead: followed by abc
(?!abc)
Negative lookahead: not followed by abc
(?<=abc)
Positive lookbehind: preceded by abc
(?<!abc)
Negative lookbehind: not preceded by abc
\d(?=px)
Digit only if followed by px
(?<=\$)\d+
Digits only if preceded by a dollar sign

Flags & modifiers

10
g
Global: find all matches, not just the first
i
Case-insensitive matching
m
Multiline: ^ and $ match line breaks
s
Dotall: . also matches newline
u
Unicode mode (full code points)
x
Extended: ignore whitespace, allow comments
y
Sticky: match from lastIndex (JS)
(?i)
Inline case-insensitive flag (PCRE)
(?im)
Combine inline flags
(?i:abc)
Scoped inline flag for a group

Escapes & special chars

11
\.
Literal dot
\\
Literal backslash
\/
Literal forward slash (in /.../ literals)
\t
Tab character
\n
Newline (line feed)
\r
Carriage return
\f
Form feed
\0
Null character
\xFF
Character by two-digit hex code
\x{00E9}
Unicode code point by hex (PCRE)
\Qabc\E
Quote a literal block (PCRE)

Common token shortcuts

10
[0-9]
Single digit, same as \d
[a-fA-F0-9]
A single hexadecimal digit
\d+
One or more digits (whole number)
\w+
One or more word characters
\s+
One or more whitespace characters
.*
Any run of characters (greedy)
.*?
Any run of characters (lazy)
[^\s]+
One or more non-whitespace characters
\b\w+\b
A whole word
(?:\r\n|\n|\r)
Any line ending

Practical patterns

10
^[\w.+-]+@[\w-]+\.[\w.-]+$
Simple email address
https?:\/\/[^\s]+
HTTP or HTTPS URL
\b(?:\d{1,3}\.){3}\d{1,3}\b
IPv4 address
#?[a-fA-F0-9]{6}\b
Six-digit hex color
\d{4}-\d{2}-\d{2}
Date in YYYY-MM-DD format
\+?\d[\d\s-]{7,}\d
Phone number (loose)
[a-z0-9]+(?:-[a-z0-9]+)*
URL slug (lowercase, hyphens)
^\s+|\s+$
Leading or trailing whitespace (trim)
\s{2,}
Two or more consecutive spaces
<[^>]+>
An HTML tag (naive)

Unicode properties

10
\p{L}
Any kind of letter from any language
\P{L}
Any character that is not a letter
\p{N}
Any kind of numeric character
\p{Lu}
An uppercase letter
\p{Ll}
A lowercase letter
\p{P}
Any punctuation character
\p{Sc}
A currency symbol
\p{Han}
A Han (Chinese) script character
\p{Emoji}
An emoji character (where supported)
\p{Greek}
A character from the Greek script

Không có mục nào khớp với “:q”.


Giới thiệu về Tài liệu tham khảo nhanh Regex

Bảng tra cứu regex này là tài liệu tham khảo gọn gàng về cú pháp biểu thức chính quy: lớp ký tự, anchor và ranh giới, quantifier, nhóm và backreference, lookaround, cờ và bộ điều chỉnh, escape và ký tự đặc biệt, các lối tắt token phổ biến, các mẫu thực dụng dựng sẵn, cùng thuộc tính Unicode.

Regex đúng là định nghĩa của cú pháp "viết một lần" — các token ngắn gọn và dễ gây nhầm lẫn, đặc biệt là lookahead so với lookbehind, quantifier tham lam so với lười biếng, và các dạng nhóm khác nhau. Mỗi dòng hiển thị một token hoặc mẫu bên cạnh mô tả bằng ngôn ngữ thông thường về những gì nó khớp.

Bảng kết thúc với các mẫu thực dụng bạn có thể sao chép trực tiếp, và giống mọi bảng tra cứu khác ở đây, nó miễn phí và chạy phía client: tìm kiếm trực tiếp, mục lục cố định, sao chép bằng một cú click trên mỗi token và nút in cho một tài liệu tham khảo regex trên giấy.

Cách sử dụng Tài liệu tham khảo nhanh Regex

  1. Lướt qua các phần, từ Character classes và Anchors & boundaries đến Practical patterns và Unicode properties.
  2. Tìm một token hoặc khái niệm như lookahead, \d hoặc lazy để lọc bảng ngay lập tức.
  3. Nhảy đến Practical patterns khi bạn cần một biểu thức dựng sẵn để điều chỉnh.
  4. Nhấp vào một token hoặc mẫu, hoặc biểu tượng sao chép của nó, để sao chép vào code hoặc một công cụ kiểm tra regex.
  5. In bảng — cú pháp regex là một thứ kinh điển nên giữ trên giấy.

Câu hỏi thường gặp

Mười phần: lớp ký tự, anchor và ranh giới, quantifier, nhóm và backreference, lookaround, cờ và bộ điều chỉnh, escape và ký tự đặc biệt, lối tắt token, các mẫu thực dụng, cùng thuộc tính Unicode.

Có. Phần mẫu thực dụng chứa các biểu thức hoàn chỉnh cho các tác vụ khớp phổ biến mà bạn có thể sao chép và điều chỉnh, thay vì phải lắp ráp từng token một.

Có. Phần lookaround liệt kê lookahead và lookbehind dạng dương và âm song song với mô tả — một trong những góc gây nhầm lẫn nhất của cú pháp regex.

Cú pháp hiển thị là phần cốt lõi được chia sẻ rộng rãi, dùng bởi các engine chính thống, bao gồm lớp ký tự, quantifier, nhóm, lookaround, cờ và escape thuộc tính Unicode. Các phần mở rộng riêng của từng engine có thể khác nhau, vì vậy hãy kiểm tra các cấu trúc bất thường trong ngôn ngữ mục tiêu của bạn.

Có, hoàn toàn miễn phí — có thể tìm kiếm, in được và hiển thị hoàn toàn trong trình duyệt của bạn.


Tìm kiếm phổ biến
regex cheat sheet regular expression syntax regex character classes regex lookahead and lookbehind regex quantifiers list regex flags reference common regex patterns regex email pattern
Cần trợ giúp?
Gặp sự cố với công cụ này? Hãy cho đội ngũ của chúng tôi biết.
Báo cáo sự cố

Thêm công cụ miễn phí này vào trang web của riêng bạn — sao chép và dán mã bên dưới.