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

加载更多搜索结果...

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

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

正则表达式参考:特殊组

功能语法说明范例.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
注解 (?#comment) (?# 和 ) 之间的所有内容都会被 regex 引擎忽略。 a(?#foobar)b 会配对 ab 是否是是是是是是否否是是是否ECMA是否否否否否否否
分支重设群组 (?|regex) 如果分支重设群组内的 regex 具有多个具有捕获组的选项,则所有选项中的捕获组编号都相同。 (x)(?|(a)|(bc)|(def))\2 会配对 xaa、xbcbc 或 xdefdef,其中第一个群组截取 x,第二个群组截取 a、bc 或 def 否否5.107.2是5.2.4是是否否否否否否ECMA
1.42–1.83
否否否否否否否否
原子组 (?>正则表达式) 原子组可防止正则表达式引擎在找到群组的配对后回溯到群组中。如果正则表达式的其余部分失败,如果量词或交替使其成为可选的,引擎可能会回溯到群组。但它不会回溯到群组中以尝试群组的其他排列。 a(?>bc|b)c 配对 abcc 但不配对 abc 是是是是是是是是否否否否是否ECMA否否否否否否否否
正向先行断言 (?=正则表达式) 在先行断言内部模式可以配对的位置配对。仅配对位置。它不消耗任何字符或扩充配对。在类似 one(?=two)three 的模式中,two 和 three 都必须在 one 的配对结束的位置配对。 t(?=s) 配对 streets 中第二个 t。 是是是是是是是是是是是是是ECMAECMA是否否否否否否否
负向先行断言 (?!正则表达式) 与正向先行断言类似,但负向先行断言仅在先行断言内部的正则表达式无法配对时才会成功。 t(?!s) 配对 streets 中第一个 t。 是是是是是是是是是是是是是ECMAECMA是否否否否否否否
正向后行断言 (?<=正则表达式) 如果先行断言内部的模式可以在该位置结束时配对,则在该位置配对。 (?<=s)t 配对 streets 中第一个 t。 是是是是是是是是是否是是1.9否ECMA否否否否否否否否
负向后行断言 (?<!正则表达式) 如果先行断言内部的模式无法在该位置结束时配对,则在该位置配对。 (?<!s)t 配对 streets 中第二个 t。 是是是是是是是是是否是是1.9否ECMA否否否否否否否否
后行断言 (?<=正则表达式|较长的正则表达式) 后行断言内的选项长度可能不同。 (?<=is|e)t 配对 twisty streets 中第二个和第四个 t。 是是5.30是是是是是是不适用是否1.9不适用ECMA
1.38–1.43
不适用不适用不适用不适用不适用不适用不适用不适用
后行断言 (?<=x{n,m}) 具有有限最大重复次数的量词可用于后行断言中。 (?<=s\w{1,7})t 仅配对 twisty streets 中的第四个 t。 是6
4 失败
5.30 失败否否否否否是不适用是否否不适用否不适用不适用不适用不适用不适用不适用不适用不适用
后行断言 (?<=正则表达式) 完整的正则表达式语法可以用在反向后查中。 (?<=s\w+)t 仅配对 twisty streets 中的第四个 t。 是13否否否否否否是不适用是否否不适用否不适用不适用不适用不适用不适用不适用不适用不适用
后行断言 (group)(?<=\1) 反向引用可以用在反向后查中。反向后查中禁止的语法在被参照的捕获组中也禁止使用。 (\w).+(?<=\1) 在 twisty streets 中配对 twisty street。 是否否否10.237.3.0否4.0.0是不适用是3.5否不适用否不适用不适用不适用不适用不适用不适用不适用不适用
将文本排除在正则表达式配对之外 \K 正则表达式左侧部分配对到的文本会从整体正则表达式配对中省略。除此之外,正则表达式会从左到右正常配对。\K 左侧的捕获组会像平常一样截取。 s\Kt 仅配对 streets 中的第一个 t。 否否5.107.2是5.2.4是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
反向后查条件式 (?(?=regex)then|else) 其中 (?=regex) 是任何有效的反向后查,而 then 和 else 是任何有效的正则表达式 如果反向后查成功,则「then」部分必须配对才能让整体正则表达式配对。如果反向后查失败,则「else」部分必须配对才能让整体正则表达式配对。反向后查的长度为零。「then」和「else」部分会像一般的正则表达式一样消耗其配对。 (?(?<=a)b|c) 在 babxcac 中配对第二个 b 和第一个 c。 是否是是是是是是否否否否否否ECMA否否否否否否否否
隐含的反向后查条件式 (?(regex)then|else) 其中 regex、then 和 else 是任何有效的正则表达式,且 regex 不是捕获组的名称 如果「regex」不是捕获组的名称,则会将其解释为反向后查,就像你写了 (?(?=regex)then|else) 一样。如果反向后查成功,则「then」部分必须配对才能让整体正则表达式配对。如果反向后查失败,则「else」部分必须配对才能让整体正则表达式配对。反向后查的长度为零。「then」和「else」部分会像一般的正则表达式一样消耗其配对。 (?(\d{2})7|c) 符合 747c 中的第一个 7 和 c 是否否否否否否否否否否否否否否否否否否否否否否
命名条件 (?(名称)然后|否则) 其中 名称 是捕获组的名称,然后 和 否则 是任何有效的正则表达式 如果具有给定名称的捕获组到目前为止参与了比对尝试,则「然后」部分必须符合整体正则表达式才能符合。如果捕获组到目前为止尚未参与比对,则「否则」部分必须符合整体正则表达式才能符合。 (?<one>a)?(?(one)b|c) 符合 babxcac 中的 ab、第一个 c 和第二个 c 是否否6.7是5.2.0是是否否否是否否否否否否否否否否否
命名条件 (?(<名称>)然后|否则) 其中 名称 是捕获组的名称,然后 和 否则 是任何有效的正则表达式 如果具有给定名称的捕获组到目前为止参与了比对尝试,则「然后」部分必须符合整体正则表达式才能符合。如果捕获组到目前为止尚未参与比对,则「否则」部分必须符合整体正则表达式才能符合。 (?<one>a)?(?(<one>)b|c) 符合 babxcac 中的 ab、第一个 c 和第二个 c 否否5.107.0是5.2.2是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
命名条件 (?('名称')然后|否则) 其中 名称 是捕获组的名称,然后 和 否则 是任何有效的正则表达式 如果具有给定名称的捕获组到目前为止参与了比对尝试,则「然后」部分必须符合整体正则表达式才能符合。如果捕获组到目前为止尚未参与比对,则「否则」部分必须符合整体正则表达式才能符合。 (?'one'a)?(?('one')b|c) 符合 babxcac 中的 ab、第一个 c 和第二个 c 否否5.107.0是5.2.2是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
条件 (?(1)然后|否则) 其中 1 是捕获组的编号,然后 和 否则 是任何有效的正则表达式 如果引用的捕获组到目前为止参与了比对尝试,则「然后」部分必须符合整体正则表达式才能符合。如果捕获组到目前为止尚未参与比对,则「否则」部分必须符合整体正则表达式才能符合。 (a)?(?(1)b|c) 符合 babxcac 中的 ab、第一个 c 和第二个 c 是否是是是是是是否否否是2.0否ECMA否否否否否否否否
相对条件 (?(-1)然后|否则) 其中 -1 是负整数,然后 和 否则 是任何有效的正则表达式 条件会测试捕获组,该群组可通过从条件正前方的最右边开始,从右到左计算指定数量的命名或编号捕获组的打开括号来找到。如果引用的捕获组到目前为止参与了比对尝试,则「然后」部分必须符合整体正则表达式才能符合。如果捕获组到目前为止尚未参与比对,则「否则」部分必须符合整体正则表达式才能符合。 (a)?(?(-1)b|c) 符合 ab、babxcac 中的第一个 c 和第二个 c 否否否7.2是5.2.4是是否否否否否否否否否否否否否否否
向前条件 (?(+1)then|else),其中 +1 为正整数,而 then 和 else 为任何有效的正则表达式 条件会测试从「then」部分开始,从左到右依序计算命名的或编号的捕获组的打开括号数量,并找出符合指定数字的捕获组。如果参考的捕获组参与到目前为止的比对尝试,则「then」部分必须符合才能让整体正则表达式符合。如果捕获组到目前为止尚未参与比对,则「else」部分必须符合才能让整体正则表达式符合。 ((?(+1)b|c)(d)?){2} 符合 bdbdccxcdcxcdb 中的 cc 和 cdb 否否否7.2是5.2.4是是否否否否否否否否否否否否否否否
条件 (?(+1)then|else),其中 1 是捕获组的数字,而 then 和 else 为任何有效的正则表达式 + 会被忽略,而数字会被视为捕获组的绝对参考。如果参考的捕获组参与到目前为止的比对尝试,则「then」部分必须符合才能让整体正则表达式符合。如果捕获组到目前为止尚未参与比对,则「else」部分必须符合才能让整体正则表达式符合。 (a)?(?(+1)b|c) 符合 babxcac 中的 ab、第一个 c 和第二个 c 否否否否否否否否否否否是否否否否否否否否否否否
功能语法说明范例.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
正規表示式參考:特殊群組
  • 简
  • 繁
  • En
關於正規表示式 » 正規表示式參考 » 正規表示式參考:特殊群組

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

正規表示式參考:特殊群組

功能語法說明範例.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
註解 (?#comment) (?# 和 ) 之間的所有內容都會被 regex 引擎忽略。 a(?#foobar)b 會配對 ab 是否是是是是是是否否是是是否ECMA是否否否否否否否
分支重設群組 (?|regex) 如果分支重設群組內的 regex 具有多個具有擷取群組的選項,則所有選項中的擷取群組編號都相同。 (x)(?|(a)|(bc)|(def))\2 會配對 xaa、xbcbc 或 xdefdef,其中第一個群組擷取 x,第二個群組擷取 a、bc 或 def 否否5.107.2是5.2.4是是否否否否否否ECMA
1.42–1.83
否否否否否否否否
原子群組 (?>正規表示法) 原子群組可防止正規表示法引擎在找到群組的配對後回溯到群組中。如果正規表示法的其餘部分失敗,如果量詞或交替使其成為可選的,引擎可能會回溯到群組。但它不會回溯到群組中以嘗試群組的其他排列。 a(?>bc|b)c 配對 abcc 但不配對 abc 是是是是是是是是否否否否是否ECMA否否否否否否否否
正向先行斷言 (?=正規表示法) 在先行斷言內部模式可以配對的位置配對。僅配對位置。它不消耗任何字元或擴充配對。在類似 one(?=two)three 的模式中,two 和 three 都必須在 one 的配對結束的位置配對。 t(?=s) 配對 streets 中第二個 t。 是是是是是是是是是是是是是ECMAECMA是否否否否否否否
負向先行斷言 (?!正規表示法) 與正向先行斷言類似,但負向先行斷言僅在先行斷言內部的正規表示法無法配對時才會成功。 t(?!s) 配對 streets 中第一個 t。 是是是是是是是是是是是是是ECMAECMA是否否否否否否否
正向後行斷言 (?<=正規表示法) 如果先行斷言內部的模式可以在該位置結束時配對,則在該位置配對。 (?<=s)t 配對 streets 中第一個 t。 是是是是是是是是是否是是1.9否ECMA否否否否否否否否
負向後行斷言 (?<!正規表示法) 如果先行斷言內部的模式無法在該位置結束時配對,則在該位置配對。 (?<!s)t 配對 streets 中第二個 t。 是是是是是是是是是否是是1.9否ECMA否否否否否否否否
後行斷言 (?<=正規表示法|較長的正規表示法) 後行斷言內的選項長度可能不同。 (?<=is|e)t 配對 twisty streets 中第二個和第四個 t。 是是5.30是是是是是是不適用是否1.9不適用ECMA
1.38–1.43
不適用不適用不適用不適用不適用不適用不適用不適用
後行斷言 (?<=x{n,m}) 具有有限最大重複次數的量詞可用於後行斷言中。 (?<=s\w{1,7})t 僅配對 twisty streets 中的第四個 t。 是6
4 失敗
5.30 失敗否否否否否是不適用是否否不適用否不適用不適用不適用不適用不適用不適用不適用不適用
後行斷言 (?<=正規表示法) 完整的正規表示法語法可以用在反向後查中。 (?<=s\w+)t 僅配對 twisty streets 中的第四個 t。 是13否否否否否否是不適用是否否不適用否不適用不適用不適用不適用不適用不適用不適用不適用
後行斷言 (group)(?<=\1) 反向參照可以用在反向後查中。反向後查中禁止的語法在被參照的擷取群組中也禁止使用。 (\w).+(?<=\1) 在 twisty streets 中配對 twisty street。 是否否否10.237.3.0否4.0.0是不適用是3.5否不適用否不適用不適用不適用不適用不適用不適用不適用不適用
將文字排除在正規表示法配對之外 \K 正規表示法左側部分配對到的文字會從整體正規表示法配對中省略。除此之外,正規表示法會從左到右正常配對。\K 左側的擷取群組會像平常一樣擷取。 s\Kt 僅配對 streets 中的第一個 t。 否否5.107.2是5.2.4是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
反向後查條件式 (?(?=regex)then|else) 其中 (?=regex) 是任何有效的反向後查,而 then 和 else 是任何有效的正規表示法 如果反向後查成功,則「then」部分必須配對才能讓整體正規表示法配對。如果反向後查失敗,則「else」部分必須配對才能讓整體正規表示法配對。反向後查的長度為零。「then」和「else」部分會像一般的正規表示法一樣消耗其配對。 (?(?<=a)b|c) 在 babxcac 中配對第二個 b 和第一個 c。 是否是是是是是是否否否否否否ECMA否否否否否否否否
隱含的反向後查條件式 (?(regex)then|else) 其中 regex、then 和 else 是任何有效的正規表示法,且 regex 不是擷取群組的名稱 如果「regex」不是擷取群組的名稱,則會將其解釋為反向後查,就像你寫了 (?(?=regex)then|else) 一樣。如果反向後查成功,則「then」部分必須配對才能讓整體正規表示法配對。如果反向後查失敗,則「else」部分必須配對才能讓整體正規表示法配對。反向後查的長度為零。「then」和「else」部分會像一般的正規表示法一樣消耗其配對。 (?(\d{2})7|c) 符合 747c 中的第一個 7 和 c 是否否否否否否否否否否否否否否否否否否否否否否
命名條件 (?(名稱)然後|否則) 其中 名稱 是擷取群組的名稱,然後 和 否則 是任何有效的正規表示式 如果具有給定名稱的擷取群組到目前為止參與了比對嘗試,則「然後」部分必須符合整體正規表示式才能符合。如果擷取群組到目前為止尚未參與比對,則「否則」部分必須符合整體正規表示式才能符合。 (?<one>a)?(?(one)b|c) 符合 babxcac 中的 ab、第一個 c 和第二個 c 是否否6.7是5.2.0是是否否否是否否否否否否否否否否否
命名條件 (?(<名稱>)然後|否則) 其中 名稱 是擷取群組的名稱,然後 和 否則 是任何有效的正規表示式 如果具有給定名稱的擷取群組到目前為止參與了比對嘗試,則「然後」部分必須符合整體正規表示式才能符合。如果擷取群組到目前為止尚未參與比對,則「否則」部分必須符合整體正規表示式才能符合。 (?<one>a)?(?(<one>)b|c) 符合 babxcac 中的 ab、第一個 c 和第二個 c 否否5.107.0是5.2.2是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
命名條件 (?('名稱')然後|否則) 其中 名稱 是擷取群組的名稱,然後 和 否則 是任何有效的正規表示式 如果具有給定名稱的擷取群組到目前為止參與了比對嘗試,則「然後」部分必須符合整體正規表示式才能符合。如果擷取群組到目前為止尚未參與比對,則「否則」部分必須符合整體正規表示式才能符合。 (?'one'a)?(?('one')b|c) 符合 babxcac 中的 ab、第一個 c 和第二個 c 否否5.107.0是5.2.2是是否否否否2.0否ECMA
1.42–1.83
否否否否否否否否
條件 (?(1)然後|否則) 其中 1 是擷取群組的編號,然後 和 否則 是任何有效的正規表示式 如果引用的擷取群組到目前為止參與了比對嘗試,則「然後」部分必須符合整體正規表示式才能符合。如果擷取群組到目前為止尚未參與比對,則「否則」部分必須符合整體正規表示式才能符合。 (a)?(?(1)b|c) 符合 babxcac 中的 ab、第一個 c 和第二個 c 是否是是是是是是否否否是2.0否ECMA否否否否否否否否
相對條件 (?(-1)然後|否則) 其中 -1 是負整數,然後 和 否則 是任何有效的正規表示式 條件會測試擷取群組,該群組可透過從條件正前方的最右邊開始,從右到左計算指定數量的命名或編號擷取群組的開啟括號來找到。如果引用的擷取群組到目前為止參與了比對嘗試,則「然後」部分必須符合整體正規表示式才能符合。如果擷取群組到目前為止尚未參與比對,則「否則」部分必須符合整體正規表示式才能符合。 (a)?(?(-1)b|c) 符合 ab、babxcac 中的第一個 c 和第二個 c 否否否7.2是5.2.4是是否否否否否否否否否否否否否否否
向前條件 (?(+1)then|else),其中 +1 為正整數,而 then 和 else 為任何有效的正規表示式 條件會測試從「then」部分開始,從左到右依序計算命名的或編號的擷取群組的開啟括號數量,並找出符合指定數字的擷取群組。如果參考的擷取群組參與到目前為止的比對嘗試,則「then」部分必須符合才能讓整體正規表示式符合。如果擷取群組到目前為止尚未參與比對,則「else」部分必須符合才能讓整體正規表示式符合。 ((?(+1)b|c)(d)?){2} 符合 bdbdccxcdcxcdb 中的 cc 和 cdb 否否否7.2是5.2.4是是否否否否否否否否否否否否否否否
條件 (?(+1)then|else),其中 1 是擷取群組的數字,而 then 和 else 為任何有效的正規表示式 + 會被忽略,而數字會被視為擷取群組的絕對參考。如果參考的擷取群組參與到目前為止的比對嘗試,則「then」部分必須符合才能讓整體正規表示式符合。如果擷取群組到目前為止尚未參與比對,則「else」部分必須符合才能讓整體正規表示式符合。 (a)?(?(+1)b|c) 符合 babxcac 中的 ab、第一個 c 和第二個 c 否否否否否否否否否否否是否否否否否否否否否否否
功能語法說明範例.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
Regular Expression Reference: Special Groups
  • 简
  • 繁
  • En
About Regular Expressions » Regular Expressions Reference » Regular Expression Reference: Special Groups

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 Expression Reference: Special Groups

FeatureSyntaxDescriptionExample.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
Comment (?#comment) Everything between (?# and ) is ignored by the regex engine. a(?#foobar)b matches ab YESnoYESYESYESYESYESYESnonoYESYESYESnoECMAYESnonononononono
Branch reset group (?|regex) If the regex inside the branch reset group has multiple alternatives with capturing groups, then the capturing group numbers are the same in all the alternatives. (x)(?|(a)|(bc)|(def))\2 matches xaa, xbcbc, or xdefdef with the first group capturing x and the second group capturing a, bc, or def nono5.107.2YES5.2.4YESYESnonononononoECMA
1.42–1.83
nononononononono
Atomic group (?>regex) Atomic groups prevent the regex engine from backtracking back into the group after a match has been found for the group. If the remainder of the regex fails, the engine may backtrack over the group if a quantifier or alternation makes it optional. But it will not backtrack into the group to try other permutations of the group. a(?>bc|b)c matches abcc but not abc YESYESYESYESYESYESYESYESnonononoYESnoECMAnononononononono
Positive lookahead (?=regex) Matches at a position where the pattern inside the lookahead can be matched. Matches only the position. It does not consume any characters or expand the match. In a pattern like one(?=two)three, both two and three have to match at the position where the match of one ends. t(?=s) matches the second t in streets. YESYESYESYESYESYESYESYESYESYESYESYESYESECMAECMAYESnonononononono
Negative lookahead (?!regex) Similar to positive lookahead, except that negative lookahead only succeeds if the regex inside the lookahead fails to match. t(?!s) matches the first t in streets. YESYESYESYESYESYESYESYESYESYESYESYESYESECMAECMAYESnonononononono
Positive lookbehind (?<=regex) Matches at a position if the pattern inside the lookbehind can be matched ending at that position. (?<=s)t matches the first t in streets. YESYESYESYESYESYESYESYESYESnoYESYES1.9noECMAnononononononono
Negative lookbehind (?<!regex) Matches at a position if the pattern inside the lookbehind cannot be matched ending at that position. (?<!s)t matches the second t in streets. YESYESYESYESYESYESYESYESYESnoYESYES1.9noECMAnononononononono
Lookbehind (?<=regex|longer regex) Alternatives inside lookbehind can differ in length. (?<=is|e)t matches the second and fourth t in twisty streets. YESYES5.30YESYESYESYESYESYESn/aYESno1.9n/aECMA
1.38–1.43
n/an/an/an/an/an/an/an/a
Lookbehind (?<=x{n,m}) Quantifiers with a finite maximum number of repetitions can be used inside lookbehind. (?<=s\w{1,7})t matches only the fourth t in twisty streets. YES6
4 fail
5.30 failnononononoYESn/aYESnonon/anon/an/an/an/an/an/an/an/a
Lookbehind (?<=regex) The full regular expression syntax can be used inside lookbehind. (?<=s\w+)t matches only the fourth t in twisty streets. YES13nonononononoYESn/aYESnonon/anon/an/an/an/an/an/an/an/a
Lookbehind (group)(?<=\1) Backreferences can be used inside lookbehind. Syntax prohibited in lookbehind is also prohibited in the referenced capturing group. (\w).+(?<=\1) matches twisty street in twisty streets. YESnonono10.237.3.0no4.0.0YESn/aYES3.5non/anon/an/an/an/an/an/an/an/a
Keep text out of the regex match \K The text matched by the part of the regex to the left of the \K is omitted from the overall regex match. Other than that the regex is matched normally from left to right. Capturing groups to the left of the \K capture as usual. s\Kt matches only the first t in streets. nono5.107.2YES5.2.4YESYESnononono2.0noECMA
1.42–1.83
nononononononono
Lookaround conditional (?(?=regex)then|else) where (?=regex) is any valid lookaround and then and else are any valid regexes If the lookaround succeeds, the “then” part must match for the overall regex to match. If the lookaround fails, the “else” part must match for the overall regex to match. The lookaround is zero-length. The “then” and “else” parts consume their matches like normal regexes. (?(?<=a)b|c) matches the second b and the first c in babxcac YESnoYESYESYESYESYESYESnonononononoECMAnononononononono
Implicit lookahead conditional (?(regex)then|else) where regex, then, and else are any valid regexes and regex is not the name of a capturing group If “regex” is not the name of a capturing group, then it is interpreted as a lookahead as if you had written (?(?=regex)then|else). If the lookahead succeeds, the “then” part must match for the overall regex to match. If the lookahead fails, the “else” part must match for the overall regex to match. The lookaround is zero-length. The “then” and “else” parts consume their matches like normal regexes. (?(\d{2})7|c) matches the first 7 and the c in 747c YESnononononononononononononononononononononono
Named conditional (?(name)then|else) where name is the name of a capturing group and then and else are any valid regexes If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (?<one>a)?(?(one)b|c) matches ab, the first c, and the second c in babxcac YESnono6.7YES5.2.0YESYESnononoYESnonononononononononono
Named conditional (?(<name>)then|else) where name is the name of a capturing group and then and else are any valid regexes If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (?<one>a)?(?(<one>)b|c) matches ab, the first c, and the second c in babxcac nono5.107.0YES5.2.2YESYESnononono2.0noECMA
1.42–1.83
nononononononono
Named conditional (?('name')then|else) where name is the name of a capturing group and then and else are any valid regexes If the capturing group with the given name took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (?'one'a)?(?('one')b|c) matches ab, the first c, and the second c in babxcac nono5.107.0YES5.2.2YESYESnononono2.0noECMA
1.42–1.83
nononononononono
Conditional (?(1)then|else) where 1 is the number of a capturing group and then and else are any valid regexes If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (a)?(?(1)b|c) matches ab, the first c, and the second c in babxcac YESnoYESYESYESYESYESYESnononoYES2.0noECMAnononononononono
Relative conditional (?(-1)then|else) where -1 is a negative integer and then and else are any valid regexes Conditional that tests the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting immediately before the conditional. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (a)?(?(-1)b|c) matches ab, the first c, and the second c in babxcac nonono7.2YES5.2.4YESYESnonononononononononononononono
Forward conditional (?(+1)then|else) where +1 is a positive integer and then and else are any valid regexes Conditional that tests the capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from left to right starting at the “then” part of conditional. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. ((?(+1)b|c)(d)?){2} matches cc and cdb in bdbdccxcdcxcdb nonono7.2YES5.2.4YESYESnonononononononononononononono
Conditional (?(+1)then|else) where 1 is the number of a capturing group and then and else are any valid regexes The + is ignored and the number is taken as an absolute reference to a capturing group. If the referenced capturing group took part in the match attempt thus far, the “then” part must match for the overall regex to match. If the capturing group did not take part in the match thus far, the “else” part must match for the overall regex to match. (a)?(?(+1)b|c) matches ab, the first c, and the second c in babxcac nononononononononononoYESnonononononononononono
FeatureSyntaxDescriptionExample.NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
©2015-2025 艾丽卡 support@alaica.com