所有工具
免費

可搜尋、可列印的正規表示式參考手冊——字元類別、錨點、量詞、群組、環視、旗標以及現成的比對模式。免費。

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

沒有條目符合「:q」。


關於 Regex 速查表

這份正規表示式小抄是正規表示式語法的精簡參考資料:字元類別、錨點與邊界、量詞、群組與反向參照、環顧、旗標與修飾符、跳脫字元與特殊字元、常用符記捷徑、實用的現成模式,以及 Unicode 屬性。

正規表示式是「一寫就忘」語法的代表——符記精簡且容易搞混,尤其是前瞻與後顧、貪婪與惰性量詞,以及各種群組形式。每一列都會展示一個符記或模式,並搭配一句白話說明其比對內容。

此小抄最後附上可直接複製使用的實用模式,和這裡的每一份小抄一樣,它免費且在用戶端運作:即時搜尋、固定式目錄、每個符記都可一鍵複製,還有列印按鈕可製作紙本正規表示式參考資料。

如何使用 Regex 速查表

  1. 瀏覽各章節,從字元類別與錨點及邊界,到實用模式與 Unicode 屬性。
  2. 搜尋符記或概念,例如 lookahead、\d 或 lazy,即可立即篩選小抄。
  3. 需要現成表達式可套用時,跳到實用模式章節。
  4. 點擊符記或模式,或其複製圖示,即可將其複製到程式碼或正規表示式測試工具中。
  5. 列印小抄——正規表示式語法本來就很適合列印在紙上保存。

常見問題

共十個章節:字元類別、錨點與邊界、量詞、群組與反向參照、環顧、旗標與修飾符、跳脫字元與特殊字元、符記捷徑、實用模式,以及 Unicode 屬性。

有的。實用模式章節收錄了針對常見比對任務的完整表達式,可直接複製調整使用,而不必逐一符記組裝。

有的。環顧章節將正向與負向的前瞻及後顧並列展示並附上說明——這是正規表示式語法中最常被搞混的部分之一。

所展示的語法是主流引擎廣泛共用的核心部分,包括字元類別、量詞、群組、環顧與 Unicode 屬性跳脫。不同引擎的擴充功能各有差異,因此遇到不常見的結構時,請在目標語言中測試。

是的,完全免費——可搜尋、可列印,且完全在你的瀏覽器中呈現。


熱門搜尋
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
需要協助?
使用此工具時遇到問題?請告訴我們的團隊。
回報問題

將此免費工具新增到你自己的網站 — 複製並貼上下面的程式碼。