正则表达式参考正则表达式参考正则表达式参考正则表达式参考
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2024年3月5日
类别
  • 正则表达式
标签
正则表达式参考
  • 简
  • 繁
  • En
关于正则表达式 » 正则表达式参考 » 正则表达式参考

正则表达式参考
简介
目录
快速参考
字符
基本功能
字符类别
简写
锚点
字词边界
量词
Unicode
捕获组和反向引用
命名组和反向引用
特殊组
模式修改器
递归和平衡组
替换参考
字符
配对文本和反向引用
内容和大小写转换
条件式
更多网站信息
简介
正则表达式快速入门
正则表达式教程
替换字符串教程
应用程序和语言
正则表达式范例
正则表达式参考
替换字符串参考

正则表达式参考

本网站上的正则表达式参考既是所有可用正则表达式语法的参考,也是在 教学 中讨论的正则表达式风格所支持功能的比较。 参考表格 包含了大量的信息。若要充分利用它们,请遵循此说明以了解如何阅读它们。

表格针对每个正则表达式功能有六个字段。前四个字段说明该功能。

功能功能名称,同时也是教学中相关章节的链接。
语法此功能的实际正则表达式语法。如果语法是固定的,则会直接显示。如果语法有变量元素,则会说明语法。
说明功能用途的摘要。
范例展示该功能的正则表达式。

最后两栏表示您选择的两种正则表达式风格是否支持此特定功能。您可以使用表格上方的下拉列表变更风格。有许多可能的指针。

是此风格的所有版本都支持此功能。
3.0此风格的版本 3.0 和所有后续版本都支持此功能。早期版本不支持。
仅 2.0只有版本 2.0 支持此功能。早期和后续版本不支持。
2.0–2.9仅版本 2.0 到 2.9 支持此功能。早期和后续版本不支持。
Unicode此功能在所有版本的此风格中都适用于 Unicode 字符。
编码页此功能在所有版本的此风格中都适用于主动编码页中的字符。
ASCII此功能在所有版本的此风格中仅适用于 ASCII 字符。
3.0 Unicode此功能在版本 3.0 和后续版本的此风格中都适用于 Unicode 字符。早期版本完全不支持。
3.0 Unicode
2.0 ASCII
此功能在版本 3.0 和后续版本的此风格中都适用于 Unicode 字符。在版本 2.0 到 2.9 中适用于 ASCII 字符。早期版本完全不支持。
3.0 Unicode
2.0 编码页
此功能在版本 3.0 和后续版本的此风格中都适用于 Unicode 字符。在版本 2.0 到 2.9 中适用于主动编码页中的字符。早期版本完全不支持。
字符串正则表达式风格不支持此语法。但是,此正则表达式风格通常用于编程语言中的字符串常数支持此语法。
3.0
1.0 字符串
此正则表达式风格的版本 3.0 和后续版本支持此语法。正则表达式风格的早期版本不支持此语法。但是,此正则表达式风格通常用于编程语言中的字符串常数自版本 1.0 起就支持此语法。
选项如果您设置特定选项或在前面加上特定 模式修改器,此正则表达式风格的所有版本都支持此功能。
选项
3.0
如果您设置特定选项或在前面加上特定 模式修改器,此正则表达式风格的版本 3.0 和所有后续版本都支持此功能。早期版本不支持语法或不支持模式修改器,无法将语法的行为变更为功能所描述的内容。
3.0
2.0 失败
此正则表达式风格的版本 3.0 和所有后续版本都支持此功能。版本 2.0 所有 3.0 之前的后续版本都辨识语法,但永远无法比对此正则表达式记号。2.0 之前的版本不支持语法。
否此风格的任何版本都不支持此功能。未说明此语法实际上运行什么动作。相同语法可能用于参考表格中其他地方指出的不同功能。或者,此语法可能会触发错误,或可能被解译为纯文本。
不适用此功能不适用于此正则表达式风格。描述参考表格中先前介绍的特定语法行为的功能会显示不适用于完全不支持该语法的风格。
失败此风格辨识语法,且使用它的正则表达式运作,但此特定正则表达式代码始终无法配对。只有当此代码通过交替或量词变成选用时,正则表达式才能找到配对。
2.0–2.9 失败2.0 至 2.9 版辨识语法,但始终无法配对此正则表达式代码。较早和较新的版本不辨识语法或将其视为语法错误。
忽略此风格辨识语法,但它没有运行任何有用的动作。此特定正则表达式代码始终会找到长度为零的配对。
错误此风格辨识语法,但将其视为语法错误。

当此图例显示「所有版本」或「没有版本」时,表示参考表格涵盖的每个风格的所有或没有版本

.NET1.0–1.1:原始 .NET 架构的前 2 个版本
2.0–7.0:.NET Framework 2.0–4.8、.NET Core 1.0.0–3.1.0 和 .NET 5.0–7.0
1.0–7.0:.NET Framework 和 .NET Core 的所有版本
Java4–21
Perl5.8–5.32
PCRE4.0–8.45
PCRE210.00–10.39
PHP5.0.0–8.1.24
DelphiXE–XE8 和 10–10.4 和 11;仅 TRegEx;也适用于 C++Builder XE–XE8 和 10–10.4 和 11
R2.14.0–4.2.1
JavaScriptChrome、Edge 和 Firefox 的最新版本
VBScript怪异模式中的 VBscript 和 Internet Explorer
XRegExp2.0.0–5.1.0
Python2.4–3.12
Ruby1.8–3.2
std::regexVisual C++ 2008–2022 (Dinkumware std 函数库)
boost::regex1.38–1.39 & 1.42–1.83
Tcl ARE8.4–8.6
POSIX BREIEEE Std 1003.1
POSIX EREIEEE Std 1003.1
GNU BRE
GNU ERE
Oracle10gR1、10gR2、11gR1、11gR2、12c
XML1.0–1.1
XPath2.0–3.1

对于 .NET 版本,某些功能会标示为「ECMA」或「非 ECMA」。这表示该功能仅在设置 RegexOptions.ECMAScript 或未设置时才受支持。当设置 RegexOptions.ECMAScript 时,标示为「非 ECMA Unicode」的功能会比对 ASCII 字符,而未设置 RegexOptions.ECMAScript 时则会比对 Unicode 字符。适用于 .NET 2.0 或更新版本的任何功能也适用于任何版本的 .NET Core。Visual Studio IDE 从 VS 2012 开始使用非 ECMA .NET 版本。

对于 std::regex 和 boost::regex 版本,有额外的指针 ECMA、basic、extended、grep、egrep 和 awk。如果出现其中一个或多个指针,表示仅在编译正则表达式时指定其中一个语法时才支持该功能。当在宽字符字符串上使用 std::wregex 或 boost::wregex 时,具有 Unicode 指针的功能会比对 Unicode 字符。在替换字符串参考中,额外的指针为 sed 和 default。如果出现其中一个指针,表示仅在将 match_flag_type::format_sed 传递给 regex_replace() 或未传递时才支持该功能。对于 boost,还有一个额外的替换指针「all」,表示仅在将 match_flag_type::format_all 传递给 regex_replace() 时才支持该功能。

对于 PCRE2 版本,某些替换字符串功能会标示为「extended」。这表示仅在将 PCRE2_SUBSTITUTE_EXTENDED 传递给 pcre2_substitute 时才支持该功能。

正規表示式參考
  • 简
  • 繁
  • En
關於正規表示式 » 正規表示式參考 » 正規表示式參考

正規表示式參考
簡介
目錄
快速參考
字元
基本功能
字元類別
簡寫
錨點
字詞邊界
量詞
Unicode
擷取群組和反向參照
命名群組和反向參照
特殊群組
模式修改器
遞迴和平衡群組
替換參考
字元
配對文字和反向參照
內容和大小寫轉換
條件式
更多網站資訊
簡介
正規表示式快速入門
正規表示式教學
替換字串教學
應用程式和語言
正規表示式範例
正規表示式參考
替換字串參考

正規表示式參考

本網站上的正規表示式參考既是所有可用正規表示式語法的參考,也是在 教學 中討論的正規表示式風格所支援功能的比較。 參考表格 包含了大量的資訊。若要充分利用它們,請遵循此說明以了解如何閱讀它們。

表格針對每個正規表示式功能有六個欄位。前四個欄位說明該功能。

功能功能名稱,同時也是教學中相關章節的連結。
語法此功能的實際正規表示式語法。如果語法是固定的,則會直接顯示。如果語法有變數元素,則會說明語法。
說明功能用途的摘要。
範例展示該功能的正規表示式。

最後兩欄表示您選擇的兩種正規表示式風格是否支援此特定功能。您可以使用表格上方的下拉式清單變更風格。有許多可能的指標。

是此風格的所有版本都支援此功能。
3.0此風格的版本 3.0 和所有後續版本都支援此功能。早期版本不支援。
僅 2.0只有版本 2.0 支援此功能。早期和後續版本不支援。
2.0–2.9僅版本 2.0 到 2.9 支援此功能。早期和後續版本不支援。
Unicode此功能在所有版本的此風格中都適用於 Unicode 字元。
編碼頁此功能在所有版本的此風格中都適用於主動編碼頁中的字元。
ASCII此功能在所有版本的此風格中僅適用於 ASCII 字元。
3.0 Unicode此功能在版本 3.0 和後續版本的此風格中都適用於 Unicode 字元。早期版本完全不支援。
3.0 Unicode
2.0 ASCII
此功能在版本 3.0 和後續版本的此風格中都適用於 Unicode 字元。在版本 2.0 到 2.9 中適用於 ASCII 字元。早期版本完全不支援。
3.0 Unicode
2.0 編碼頁
此功能在版本 3.0 和後續版本的此風格中都適用於 Unicode 字元。在版本 2.0 到 2.9 中適用於主動編碼頁中的字元。早期版本完全不支援。
字串正規表示式風格不支援此語法。但是,此正規表示式風格通常用於程式語言中的字串常數支援此語法。
3.0
1.0 字串
此正規表示式風格的版本 3.0 和後續版本支援此語法。正規表示式風格的早期版本不支援此語法。但是,此正規表示式風格通常用於程式語言中的字串常數自版本 1.0 起就支援此語法。
選項如果您設定特定選項或在前面加上特定 模式修改器,此正規表示式風格的所有版本都支援此功能。
選項
3.0
如果您設定特定選項或在前面加上特定 模式修改器,此正規表示式風格的版本 3.0 和所有後續版本都支援此功能。早期版本不支援語法或不支援模式修改器,無法將語法的行為變更為功能所描述的內容。
3.0
2.0 失敗
此正規表示式風格的版本 3.0 和所有後續版本都支援此功能。版本 2.0 所有 3.0 之前的後續版本都辨識語法,但永遠無法比對此正規表示式記號。2.0 之前的版本不支援語法。
否此風味的任何版本都不支援此功能。未說明此語法實際上執行什麼動作。相同語法可能用於參考表格中其他地方指出的不同功能。或者,此語法可能會觸發錯誤,或可能被解譯為純文字。
不適用此功能不適用於此正規表示式風味。描述參考表格中先前介紹的特定語法行為的功能會顯示不適用於完全不支援該語法的風味。
失敗此風味辨識語法,且使用它的正規表示式運作,但此特定正規表示式代碼始終無法配對。只有當此代碼透過交替或量詞變成選用時,正規表示式才能找到配對。
2.0–2.9 失敗2.0 至 2.9 版辨識語法,但始終無法配對此正規表示式代碼。較早和較新的版本不辨識語法或將其視為語法錯誤。
忽略此風味辨識語法,但它沒有執行任何有用的動作。此特定正規表示式代碼始終會找到長度為零的配對。
錯誤此風味辨識語法,但將其視為語法錯誤。

當此圖例顯示「所有版本」或「沒有版本」時,表示參考表格涵蓋的每個風味的所有或沒有版本

.NET1.0–1.1:原始 .NET 架構的前 2 個版本
2.0–7.0:.NET Framework 2.0–4.8、.NET Core 1.0.0–3.1.0 和 .NET 5.0–7.0
1.0–7.0:.NET Framework 和 .NET Core 的所有版本
Java4–21
Perl5.8–5.32
PCRE4.0–8.45
PCRE210.00–10.39
PHP5.0.0–8.1.24
DelphiXE–XE8 和 10–10.4 和 11;僅 TRegEx;也適用於 C++Builder XE–XE8 和 10–10.4 和 11
R2.14.0–4.2.1
JavaScriptChrome、Edge 和 Firefox 的最新版本
VBScript怪異模式中的 VBscript 和 Internet Explorer
XRegExp2.0.0–5.1.0
Python2.4–3.12
Ruby1.8–3.2
std::regexVisual C++ 2008–2022 (Dinkumware std 函式庫)
boost::regex1.38–1.39 & 1.42–1.83
Tcl ARE8.4–8.6
POSIX BREIEEE Std 1003.1
POSIX EREIEEE Std 1003.1
GNU BRE
GNU ERE
Oracle10gR1、10gR2、11gR1、11gR2、12c
XML1.0–1.1
XPath2.0–3.1

對於 .NET 版本,某些功能會標示為「ECMA」或「非 ECMA」。這表示該功能僅在設定 RegexOptions.ECMAScript 或未設定時才受支援。當設定 RegexOptions.ECMAScript 時,標示為「非 ECMA Unicode」的功能會比對 ASCII 字元,而未設定 RegexOptions.ECMAScript 時則會比對 Unicode 字元。適用於 .NET 2.0 或更新版本的任何功能也適用於任何版本的 .NET Core。Visual Studio IDE 從 VS 2012 開始使用非 ECMA .NET 版本。

對於 std::regex 和 boost::regex 版本,有額外的指標 ECMA、basic、extended、grep、egrep 和 awk。如果出現其中一個或多個指標,表示僅在編譯正規表示式時指定其中一個語法時才支援該功能。當在寬字元字串上使用 std::wregex 或 boost::wregex 時,具有 Unicode 指標的功能會比對 Unicode 字元。在替換字串參考中,額外的指標為 sed 和 default。如果出現其中一個指標,表示僅在將 match_flag_type::format_sed 傳遞給 regex_replace() 或未傳遞時才支援該功能。對於 boost,還有一個額外的替換指標「all」,表示僅在將 match_flag_type::format_all 傳遞給 regex_replace() 時才支援該功能。

對於 PCRE2 版本,某些替換字串功能會標示為「extended」。這表示僅在將 PCRE2_SUBSTITUTE_EXTENDED 傳遞給 pcre2_substitute 時才支援該功能。

Regular Expressions Reference
  • 简
  • 繁
  • En
About Regular Expressions » Regular Expressions Reference » Regular Expressions Reference

Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Unicode
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Mode Modifiers
Recursion & Balancing Groups
Replacement Reference
Characters
Matched Text & Backreferences
Context & Case Conversion
Conditionals
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference

Regular Expressions Reference

The regular expressions reference on this website functions both as a reference to all available regex syntax and as a comparison of the features supported by the regular expression flavors discussed in the tutorial. The reference tables pack an incredible amount of information. To get the most out of them, follow this legend to learn how to read them.

The tables have six columns for each regular expression feature. The first four explain the feature.

FeatureThe name of the feature, which also serves as a link to the relevant section in the tutorial.
SyntaxThe actual regex syntax for this feature. If the syntax is fixed, it is simply shown as such. If the syntax has variable elements, the syntax is described.
DescriptionSummary of what the feature does.
ExampleFunctional regular expression that demonstrates the feature.

The final two columns indicate whether your two chosen regular expression flavors support this particular feature. You can change the flavors using the drop-down lists above the table. There are many possible indicators.

YESAll versions of this flavor support this feature.
3.0Version 3.0 and all later versions of this flavor support this feature. Earlier versions do not support it.
2.0 onlyOnly version 2.0 supports this feature. Earlier and later versions do not support it.
2.0–2.9Only versions 2.0 through 2.9 supports this feature. Earlier and later versions do not support it.
UnicodeThis feature works with Unicode characters in all versions of this flavor.
code pageThis feature works with the characters in the active code page in all versions of this flavor.
ASCIIThis feature works with ASCII characters only in all versions of this flavor.
3.0 UnicodeThis feature works with Unicode characters in versions 3.0 and later of this flavor. Earlier versions do not support it at all.
3.0 Unicode
2.0 ASCII
This feature works with Unicode characters in versions 3.0 and later this flavor. It works with ASCII characters in versions 2.0 through 2.9. Earlier versions do not support it at all.
3.0 Unicode
2.0 code page
This feature works with Unicode characters in versions 3.0 and later this flavor. It works with the characters in the active code page in versions 2.0 through 2.9. Earlier versions do not support it at all.
stringThe regex flavor does not support this syntax. But string literals in the programming language that this regex flavor is normally used with do support this syntax.
3.0
1.0 string
Version 3.0 and later of this regex flavor support this syntax. Earlier versions of the regex flavor do not support this syntax. But string literals in the programming language that this regex flavor is normally used with have supported this syntax since version 1.0.
optionAll versions of this regex flavor support this feature if you set a particular option or precede it with a particular mode modifier.
option
3.0
Version 3.0 and all later versions of this regex flavor support this feature if you set a particular option or precede it with a particular mode modifier. Earlier versions either do not support the syntax at all or do not support the mode modifier to change the behavior of the syntax to what the feature describes.
3.0
2.0 fail
Version 3.0 and all later versions of this regex flavor support this feature. Version 2.0 all later releases prior to 3.0 recognize the syntax, but always fail to match this regex token. Versions prior to 2.0 do not support the syntax.
noNo version of this flavor support this feature. No indication is given as to what this syntax actually does. The same syntax may be used for a different feature which is indicated elsewhere in the reference table. Or the syntax may trigger an error or it may be interpreted as plain text.
n/aThis feature is not applicable to this regex flavor. Features that describe the behavior of certain syntax introduced earlier in the reference table show n/a for flavors that do not support that syntax at all.
failThe syntax is recognized by the flavor and regular expressions using it work, but this particular regex token always fails to match. The regex can only find matches if this token is made optional by alternation or a quantifier.
2.0–2.9 failVersions 2.0 through 2.9 recognize the syntax, but always fail to match this regex token. Earlier and later versions either don’t recognize the syntax or treat it as a syntax error.
ignoredThe syntax is recognized by the flavor but it does not do anything useful. This particular regex token always finds a zero-length match.
errorThe syntax is recognized by the flavor but it is treated as a syntax error.

When this legend says “all versions” or “no version”, that means all or none of the versions of each flavor that are covered by the reference tables:

.NET1.0–1.1: first 2 releases of the original .NET framework
2.0–7.0: .NET Framework 2.0–4.8, .NET Core 1.0.0–3.1.0, and .NET 5.0–7.0
1.0–7.0: all versions of the .NET Framework and .NET Core
Java4–21
Perl5.8–5.32
PCRE4.0–8.45
PCRE210.00–10.39
PHP5.0.0–8.1.24
DelphiXE–XE8 & 10–10.4 & 11; TRegEx only; also applies to C++Builder XE–XE8 & 10–10.4 & 11
R2.14.0–4.2.1
JavaScriptLatest versions of Chrome, Edge, and Firefox
VBScriptVBscript and Internet Explorer in quirks mode
XRegExp2.0.0–5.1.0
Python2.4–3.12
Ruby1.8–3.2
std::regexVisual C++ 2008–2022 (Dinkumware std library)
boost::regex1.38–1.39 & 1.42–1.83
Tcl ARE8.4–8.6
POSIX BREIEEE Std 1003.1
POSIX EREIEEE Std 1003.1
GNU BRE
GNU ERE
Oracle10gR1, 10gR2, 11gR1, 11gR2, 12c
XML1.0–1.1
XPath2.0–3.1

For the .NET flavor, some features are indicated with “ECMA” or “non-ECMA”. That means the feature is only supported when RegexOptions.ECMAScript is set or is not set. Features indicated with “non-ECMA Unicode” match ASCII characters when RegexOptions.ECMAScript is set and Unicode characters when RegexOptions.ECMAScript is not set. Everything that applies to .NET 2.0 or later also applies to any version of .NET Core. The Visual Studio IDE uses the non-ECMA .NET flavor starting with VS 2012.

For the std::regex and boost::regex flavor there are additional indicators ECMA, basic, extended, grep, egrep, and awk. When one or more of these appear, that means that the feature is only supported if you specify one of these grammars when compiling your regular expression. Features with Unicode indicators match Unicode characters when using std::wregex or boost::wregex on wide character strings. In the replacement string reference, the additional indicators are sed and default. When either one appears, the feature is only supported when you either pass or don’t pass match_flag_type::format_sed to regex_replace(). For boost, there is one more replacement indicator “all” that indicates the feature is only supported when you pass match_flag_type::format_all to regex_replace().

For the PCRE2 flavor, some replacement string features are indicated with “extended”. This means the feature is only supported when you pass PCRE2_SUBSTITUTE_EXTENDED to pcre2_substitute.

©2015-2025 艾丽卡 support@alaica.com