指定递归层级的反向引用指定递归层级的反向引用指定递归层级的反向引用指定递归层级的反向引用
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2024年3月5日
类别
  • 正则表达式
标签
指定递归层级的反向引用
  • 简
  • 繁
  • En
关于正则表达式 » 正则表达式教程 » 指定递归层级的反向引用

正则表达式教程
简介
目录
特殊字符
不可打印字符
正则表达式引擎内部
字符类别
字符类别减法
字符类别交集
简写字符类别
点
锚点
字词边界
交替
选择性项目
重复
群组和截取
反向引用
反向引用,第 2 部分
命名组
相对反向引用
分支重设群组
自由间距和注解
Unicode
模式修改器
原子组
独占量词
前瞻和后顾
环顾,第 2 部分
将文本保留在比对之外
条件式
平衡组
递归
子常式
无限递归
递归和量词
递归和截取
递归和反向引用
递归和回溯
POSIX 方括号表达式
零长度比对
继续比对
本网站的更多内容
简介
正则表达式快速入门
正则表达式教程
替换字符串教程
应用程序和语言
正则表达式范例
正则表达式参考
替换字符串参考

指定递归层级的反向引用

本教程中较早的主题说明了 正则表达式递归 和 正则表达式子常式。在本主题中,「递归」一词指的是整个正则表达式的递归、捕获组的递归,以及对捕获组的子常式调用。前一个主题也说明了这些功能在 Ruby 中 处理捕获组的方式不同于 Perl 和 PCRE。

Perl、PCRE 和 Boost 在退出递归时会还原捕获组。这表示 Perl、PCRE 和 Boost 中的反向引用会比对由相同递归层级的捕获组比对的相同文本。这使得可以运行诸如 比对回文 等动作。

Ruby 在退出递归时不会还原捕获组。一般反向引用 会比对与未回溯的捕获组最近一次比对相同的文本,而不论捕获组是在与反向引用相同或不同的递归层级中找到比对。基本上,Ruby 中的一般反向引用不会注意递归。

但是,尽管 Ruby 中的一般捕获组保存不会对递归有特别处理,但 Ruby 实际上会为所有递归层级的每个捕获组保存完整的比对堆栈。此堆栈甚至包含正则表达式引擎已退出的递归层级。

Ruby 中的反向引用可以比对与在反向引用评估时相对于其递归层级的任何递归层级的捕获组比对相同的文本。您可以使用 命名反向引用 的相同语法运行此动作,方法是在名称后加上符号和数字。在大部分情况下,您会使用 +0 来指定您要反向引用在相同递归层级的捕获组中重复使用文本。您可以指定正数来参照较深层递归层级的捕获组。这会是正则表达式引擎已退出的递归。您可以指定负数来参照较浅层级的捕获组。这会是仍在进行中的递归。

Ruby 中的奇数长度回文

在 Ruby 中,您可以使用 \b(?'word'(?'letter'[a-z])\g'word'\k'letter+0'|[a-z])\b 来比对回文单字,例如 a、dad、radar、racecar 和 redivider。为了让此范例保持简洁,此正则表达式只会比对长度为奇数个字母的回文单字。

让我们看看此正则表达式如何比对 radar。 字词边界 \b 比对字符串的开头。正则表达式引擎会进入捕获组「word」。[a-z] 比对 r,然后将其保存在捕获组「letter」的堆栈中,递归层级为 0。现在,正则表达式引擎会进入群组「word」的第一个递归。(?'letter'[a-z]) 比对并截取 a,递归层级为 1。正则表达式会进入群组「word」的第二个递归。(?'letter'[a-z]) 截取 d,递归层级为 2。在接下来的两个递归中,群组会截取 a 和 r,层级分别为 3 和 4。第五个递归会失败,因为字符串中没有字符可供 [a-z] 比对。正则表达式引擎必须回溯。

现在,正则表达式引擎必须尝试群组「word」内的第二个选项。正则表达式中第二个 [a-z] 比对字符串中的最后一个 r。现在,引擎会退出成功的递归,回到第三个递归,向上提升一层。

比对 \g'word' 之后,引擎会到达 \k'letter+0'。反向引用会失败,因为正则表达式引擎已经到达主旨字符串的结尾。因此,它会再次回溯。第二个选项现在会比对 a。正则表达式引擎会退出第三个递归。

正则表达式引擎再次比对 \g'word',需要再次尝试反向引用。反向引用指定 +0 或目前的递归层级,也就是 2。在此层级,捕获组比对 d。反向引用会失败,因为字符串中的下一个字符是 r。再次回溯,第二个选项会比对 d。

现在,\k'letter+0' 会比对字符串中的第二个 a。这是因为正则表达式引擎已回到第一个递归,其中捕获组比对到第一个 a。正则表达式引擎会离开第一个递归。

正则表达式引擎现在已回到所有递归之外。在此层级,捕获组保存 r。反向引用现在可以比对字符串中的最后一个 r。由于引擎不再位于任何递归中,因此会继续处理群组之后的正则表达式剩余部分。\b 会比对字符串的结尾。正则表达式已到达结尾,并传回 radar 作为整体比对结果。

反向引用至其他递归层级

如果修改我们的回文范例,就能轻松了解反向引用至其他递归层级。 abcdefedcba 也是一个回文,可以通过先前的正则表达式比对。考虑正则表达式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-1'|z)|[a-z])\b。反向引用现在想要比对捕获组堆栈中较低一层的文本。它会与字母 z 交替,以便在反向引用无法比对时,可以比对某些内容。

新的正则表达式会比对 abcdefdcbaz 等内容。经过大量比对和回溯后,第二个 [a-z] 会比对 f。正则表达式引擎会离开成功的第五个递归。捕获组「letter」已保存递归层级 0 到 4 中的比对结果 a、b、c、d 和 e。该群组的其他比对结果已回溯,因此未保留。

现在,引擎会评估反向引用 \k'letter-1'。目前的层级为 4,而反向引用指定 -1。因此,引擎会尝试比对 d,并成功。引擎会离开第四个递归。

反向引用会继续比对 c、b 和 a,直到正则表达式引擎离开第一个递归。现在,在所有递归之外,正则表达式引擎再次到达 \k'letter-1'。目前的层级为 0,而反向引用指定 -1。由于递归层级 -1 从未发生,因此反向引用无法比对。这不是错误,而只是 反向引用至未参与的捕获组。但反向引用有另一个选项。z 会比对 z,而 \b 会比对字符串的结尾。abcdefdcbaz 已成功比对。

您可以尽可能地使用它。正则表达式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-2'|z)|[a-z])\b 符合 abcdefcbazz。\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-99'|z)|[a-z])\b 符合 abcdefzzzzzz。

朝相反的方向进行,\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+1'|z)|[a-z])\b 符合 abcdefzedcb。同样地,在进行大量配对和回溯之后,第二个 [a-z] 符合 f,正则表达式引擎回到递归层级 4,而群组「letter」在递归层级 0 到 4 的堆栈中包含 a、b、c、d 和 e。

现在,引擎评估反向引用 \k'letter+1'。目前的层级是 4,而反向引用指定 +1。捕获组在递归层级 5 进行回溯。这表示我们有一个反向引用指向一个非参与群组,而无法配对。替代的 z 符合。引擎退出第四个递归。

在递归层级 3,反向引用指向递归层级 4。由于捕获组在递归层级 4 成功配对,因此它仍然在堆栈中保留该配对,即使正则表达式引擎已经退出该递归。因此,\k'letter+1' 符合 e。递归层级 3 成功退出。

反向引用继续配对 d 和 c,直到正则表达式引擎退出第一个递归。现在,在所有递归之外,正则表达式引擎再次到达 \k'letter+1'。目前的层级是 0,而反向引用指定 +1。捕获组仍然保留所有先前成功的递归层级。因此,反向引用仍然可以配对群组在第一个递归中截取的 b。现在,\b 在字符串的结尾配对。成功配对 abcdefzdcb。

您也可以朝这个方向尽情发挥。正则表达式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+2'|z)|[a-z])\b 符合 abcdefzzedc。\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+99'|z)|[a-z])\b 符合 abcdefzzzzzz。

指定遞迴層級的反向參照
  • 简
  • 繁
  • En
關於正規表示式 » 正規表示式教學 » 指定遞迴層級的反向參照

正規表示式教學課程
簡介
目錄
特殊字元
不可列印字元
正規表示式引擎內部
字元類別
字元類別減法
字元類別交集
簡寫字元類別
點
錨點
字詞邊界
交替
選擇性項目
重複
群組和擷取
反向參照
反向參照,第 2 部分
命名群組
相對反向參照
分支重設群組
自由間距和註解
Unicode
模式修改器
原子群組
獨佔量詞
前瞻和後顧
環顧,第 2 部分
將文字保留在比對之外
條件式
平衡群組
遞迴
子常式
無限遞迴
遞迴和量詞
遞迴和擷取
遞迴和反向參照
遞迴和回溯
POSIX 方括號表示式
零長度比對
繼續比對
本網站的更多內容
簡介
正規表示式快速入門
正規表示式教學課程
替換字串教學課程
應用程式和語言
正規表示式範例
正規表示式參考
替換字串參考

指定遞迴層級的反向參照

本教學課程中較早的主題說明了 正規表示式遞迴 和 正規表示式子常式。在本主題中,「遞迴」一詞指的是整個正規表示式的遞迴、擷取群組的遞迴,以及對擷取群組的子常式呼叫。前一個主題也說明了這些功能在 Ruby 中 處理擷取群組的方式不同於 Perl 和 PCRE。

Perl、PCRE 和 Boost 在退出遞迴時會還原擷取群組。這表示 Perl、PCRE 和 Boost 中的反向參照會比對由相同遞迴層級的擷取群組比對的相同文字。這使得可以執行諸如 比對迴文 等動作。

Ruby 在退出遞迴時不會還原擷取群組。一般反向參照 會比對與未回溯的擷取群組最近一次比對相同的文字,而不論擷取群組是在與反向參照相同或不同的遞迴層級中找到比對。基本上,Ruby 中的一般反向參照不會注意遞迴。

但是,儘管 Ruby 中的一般擷取群組儲存不會對遞迴有特別處理,但 Ruby 實際上會為所有遞迴層級的每個擷取群組儲存完整的比對堆疊。此堆疊甚至包含正規表示式引擎已退出的遞迴層級。

Ruby 中的反向參照可以比對與在反向參照評估時相對於其遞迴層級的任何遞迴層級的擷取群組比對相同的文字。您可以使用 命名反向參照 的相同語法執行此動作,方法是在名稱後加上符號和數字。在大部分情況下,您會使用 +0 來指定您要反向參照在相同遞迴層級的擷取群組中重複使用文字。您可以指定正數來參照較深層遞迴層級的擷取群組。這會是正規表示式引擎已退出的遞迴。您可以指定負數來參照較淺層級的擷取群組。這會是仍在進行中的遞迴。

Ruby 中的奇數長度迴文

在 Ruby 中,您可以使用 \b(?'word'(?'letter'[a-z])\g'word'\k'letter+0'|[a-z])\b 來比對迴文單字,例如 a、dad、radar、racecar 和 redivider。為了讓此範例保持簡潔,此正規表示式只會比對長度為奇數個字母的迴文單字。

讓我們看看此正規表示式如何比對 radar。 字詞邊界 \b 比對字串的開頭。正規表示式引擎會進入擷取群組「word」。[a-z] 比對 r,然後將其儲存在擷取群組「letter」的堆疊中,遞迴層級為 0。現在,正規表示式引擎會進入群組「word」的第一個遞迴。(?'letter'[a-z]) 比對並擷取 a,遞迴層級為 1。正規表示式會進入群組「word」的第二個遞迴。(?'letter'[a-z]) 擷取 d,遞迴層級為 2。在接下來的兩個遞迴中,群組會擷取 a 和 r,層級分別為 3 和 4。第五個遞迴會失敗,因為字串中沒有字元可供 [a-z] 比對。正規表示式引擎必須回溯。

現在,正規表示式引擎必須嘗試群組「word」內的第二個選項。正規表示式中第二個 [a-z] 比對字串中的最後一個 r。現在,引擎會退出成功的遞迴,回到第三個遞迴,向上提升一層。

比對 \g'word' 之後,引擎會到達 \k'letter+0'。反向參照會失敗,因為正規表示式引擎已經到達主旨字串的結尾。因此,它會再次回溯。第二個選項現在會比對 a。正規表示式引擎會退出第三個遞迴。

正規表示式引擎再次比對 \g'word',需要再次嘗試反向參照。反向參照指定 +0 或目前的遞迴層級,也就是 2。在此層級,擷取群組比對 d。反向參照會失敗,因為字串中的下一個字元是 r。再次回溯,第二個選項會比對 d。

現在,\k'letter+0' 會比對字串中的第二個 a。這是因為正規表示式引擎已回到第一個遞迴,其中擷取群組比對到第一個 a。正規表示式引擎會離開第一個遞迴。

正規表示式引擎現在已回到所有遞迴之外。在此層級,擷取群組儲存 r。反向參照現在可以比對字串中的最後一個 r。由於引擎不再位於任何遞迴中,因此會繼續處理群組之後的正規表示式剩餘部分。\b 會比對字串的結尾。正規表示式已到達結尾,並傳回 radar 作為整體比對結果。

反向參照至其他遞迴層級

如果修改我們的迴文範例,就能輕鬆了解反向參照至其他遞迴層級。 abcdefedcba 也是一個迴文,可以透過先前的正規表示式比對。考慮正規表示式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-1'|z)|[a-z])\b。反向參照現在想要比對擷取群組堆疊中較低一層的文字。它會與字母 z 交替,以便在反向參照無法比對時,可以比對某些內容。

新的正規表示式會比對 abcdefdcbaz 等內容。經過大量比對和回溯後,第二個 [a-z] 會比對 f。正規表示式引擎會離開成功的第五個遞迴。擷取群組「letter」已儲存遞迴層級 0 到 4 中的比對結果 a、b、c、d 和 e。該群組的其他比對結果已回溯,因此未保留。

現在,引擎會評估反向參照 \k'letter-1'。目前的層級為 4,而反向參照指定 -1。因此,引擎會嘗試比對 d,並成功。引擎會離開第四個遞迴。

反向參照會繼續比對 c、b 和 a,直到正規表示式引擎離開第一個遞迴。現在,在所有遞迴之外,正規表示式引擎再次到達 \k'letter-1'。目前的層級為 0,而反向參照指定 -1。由於遞迴層級 -1 從未發生,因此反向參照無法比對。這不是錯誤,而只是 反向參照至未參與的擷取群組。但反向參照有另一個選項。z 會比對 z,而 \b 會比對字串的結尾。abcdefdcbaz 已成功比對。

您可以盡可能地使用它。正規表示式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-2'|z)|[a-z])\b 符合 abcdefcbazz。\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-99'|z)|[a-z])\b 符合 abcdefzzzzzz。

朝相反的方向進行,\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+1'|z)|[a-z])\b 符合 abcdefzedcb。同樣地,在進行大量配對和回溯之後,第二個 [a-z] 符合 f,正規表示式引擎回到遞迴層級 4,而群組「letter」在遞迴層級 0 到 4 的堆疊中包含 a、b、c、d 和 e。

現在,引擎評估反向參照 \k'letter+1'。目前的層級是 4,而反向參照指定 +1。擷取群組在遞迴層級 5 進行回溯。這表示我們有一個反向參照指向一個非參與群組,而無法配對。替代的 z 符合。引擎退出第四個遞迴。

在遞迴層級 3,反向參照指向遞迴層級 4。由於擷取群組在遞迴層級 4 成功配對,因此它仍然在堆疊中保留該配對,即使正規表示式引擎已經退出該遞迴。因此,\k'letter+1' 符合 e。遞迴層級 3 成功退出。

反向參照繼續配對 d 和 c,直到正規表示式引擎退出第一個遞迴。現在,在所有遞迴之外,正規表示式引擎再次到達 \k'letter+1'。目前的層級是 0,而反向參照指定 +1。擷取群組仍然保留所有先前成功的遞迴層級。因此,反向參照仍然可以配對群組在第一個遞迴中擷取的 b。現在,\b 在字串的結尾配對。成功配對 abcdefzdcb。

您也可以朝這個方向盡情發揮。正規表示式 \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+2'|z)|[a-z])\b 符合 abcdefzzedc。\b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+99'|z)|[a-z])\b 符合 abcdefzzzzzz。

Backreferences That Specify a Recursion Level
  • 简
  • 繁
  • En
About Regular Expressions » Regular Expressions Tutorial » Backreferences That Specify a Recursion Level

Regex Tutorial
Introduction
Table of Contents
Special Characters
Non-Printable Characters
Regex Engine Internals
Character Classes
Character Class Subtraction
Character Class Intersection
Shorthand Character Classes
Dot
Anchors
Word Boundaries
Alternation
Optional Items
Repetition
Grouping & Capturing
Backreferences
Backreferences, part 2
Named Groups
Relative Backreferences
Branch Reset Groups
Free-Spacing & Comments
Unicode
Mode Modifiers
Atomic Grouping
Possessive Quantifiers
Lookahead & Lookbehind
Lookaround, part 2
Keep Text out of The Match
Conditionals
Balancing Groups
Recursion
Subroutines
Infinite Recursion
Recursion & Quantifiers
Recursion & Capturing
Recursion & Backreferences
Recursion & Backtracking
POSIX Bracket Expressions
Zero-Length Matches
Continuing Matches
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

Backreferences That Specify a Recursion Level

Earlier topics in this tutorial explain regular expression recursion and regular expression subroutines. In this topic the word “recursion” refers to recursion of the whole regex, recursion of capturing groups, and subroutine calls to capturing groups. The previous topic also explained that these features handle capturing groups differently in Ruby than they do in Perl and PCRE.

Perl, PCRE, and Boost restore capturing groups when they exit from recursion. This means that backreferences in Perl, PCRE, and Boost match the same text that was matched by the capturing group at the same recursion level. This makes it possible to do things like matching palindromes.

Ruby does not restore capturing groups when it exits from recursion. Normal backreferences match the text that is the same as the most recent match of the capturing group that was not backtracked, regardless of whether the capturing group found its match at the same or a different recursion level as the backreference. Basically, normal backreferences in Ruby don’t pay any attention to recursion.

But while the normal capturing group storage in Ruby does not get any special treatment for recursion, Ruby actually stores a full stack of matches for each capturing groups at all recursion levels. This stack even includes recursion levels that the regex engine has already exited from.

Backreferences in Ruby can match the same text as was matched by a capturing group at any recursion level relative to the recursion level that the backreference is evaluated at. You can do this with the same syntax for named backreferences by adding a sign and a number after the name. In most situations you will use +0 to specify that you want the backreference to reuse the text from the capturing group at the same recursion level. You can specify a positive number to reference the capturing group at a deeper level of recursion. This would be a recursion the regex engine has already exited from. You can specify a negative number to reference the capturing group a level that is less deep. This would be a recursion that is still in progress.

Odd Length Palindromes in Ruby

In Ruby you can use \b(?'word'(?'letter'[a-z])\g'word'\k'letter+0'|[a-z])\b to match palindrome words such as a, dad, radar, racecar, and redivider. To keep this example simple, this regex only matches palindrome words that are an odd number of letters long.

Let’s see how this regex matches radar. The word boundary \b matches at the start of the string. The regex engine enters the capturing group “word”. [a-z] matches r which is then stored in the stack for the capturing group “letter” at recursion level zero. Now the regex engine enters the first recursion of the group “word”. (?'letter'[a-z]) matches and captures a at recursion level one. The regex enters the second recursion of the group “word”. (?'letter'[a-z]) captures d at recursion level two. During the next two recursions, the group captures a and r at levels three and four. The fifth recursion fails because there are no characters left in the string for [a-z] to match. The regex engine must backtrack.

The regex engine must now try the second alternative inside the group “word”. The second [a-z] in the regex matches the final r in the string. The engine now exits from a successful recursion, going one level back up to the third recursion.

After matching \g'word' the engine reaches \k'letter+0'. The backreference fails because the regex engine has already reached the end of the subject string. So it backtracks once more. The second alternative now matches the a. The regex engine exits from the third recursion.

The regex engine has again matched \g'word' and needs to attempt the backreference again. The backreference specifies +0 or the present level of recursion, which is 2. At this level, the capturing group matched d. The backreference fails because the next character in the string is r. Backtracking again, the second alternative matches d.

Now, \k'letter+0' matches the second a in the string. That’s because the regex engine has arrived back at the first recursion during which the capturing group matched the first a. The regex engine exits the first recursion.

The regex engine is now back outside all recursion. At this level, the capturing group stored r. The backreference can now match the final r in the string. Since the engine is not inside any recursion any more, it proceeds with the remainder of the regex after the group. \b matches at the end of the string. The end of the regex is reached and radar is returned as the overall match.

Backreferences to Other Recursion Levels

Backreferences to other recursion levels can be easily understood if we modify our palindrome example. abcdefedcba is also a palindrome matched by the previous regular expression. Consider the regular expression \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-1'|z)|[a-z])\b. The backreference now wants a match the text one level less deep on the capturing group’s stack. It is alternated with the letter z so that something can be matched when the backreference fails to match.

The new regex matches things like abcdefdcbaz. After a whole bunch of matching and backtracking, the second [a-z] matches f. The regex engine exits from a successful fifth recursion. The capturing group “letter” has stored the matches a, b, c, d, and e at recursion levels zero to four. Other matches by that group were backtracked and thus not retained.

Now the engine evaluates the backreference \k'letter-1'. The present level is 4 and the backreference specifies -1. Thus the engine attempts to match d, which succeeds. The engine exits from the fourth recursion.

The backreference continues to match c, b, and a until the regex engine has exited the first recursion. Now, outside all recursion, the regex engine again reaches \k'letter-1'. The present level is 0 and the backreference specifies -1. Since recursion level -1 never happened, the backreference fails to match. This is not an error but simply a backreference to a non-participating capturing group. But the backreference has an alternative. z matches z and \b matches at the end of the string. abcdefdcbaz was matched successfully.

You can take this as far as you like. The regular expression \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-2'|z)|[a-z])\b matches abcdefcbazz. \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter-99'|z)|[a-z])\b matches abcdefzzzzzz.

Going in the opposite direction, \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+1'|z)|[a-z])\b matches abcdefzedcb. Again, after a whole bunch of matching and backtracking, the second [a-z] matches f, the regex engine is back at recursion level 4, and the group “letter” has a, b, c, d, and e at recursion levels zero to four on its stack.

Now the engine evaluates the backreference \k'letter+1'. The present level is 4 and the backreference specifies +1. The capturing group was backtracked at recursion level 5. This means we have a backreference to a non-participating group, which fails to match. The alternative z does match. The engine exits from the fourth recursion.

At recursion level 3, the backreference points to recursion level 4. Since the capturing group successfully matched at recursion level 4, it still has that match on its stack, even though the regex engine has already exited from that recursion. Thus \k'letter+1' matches e. Recursion level 3 is exited successfully.

The backreference continues to match d and c until the regex engine has exited the first recursion. Now, outside all recursion, the regex engine again reaches \k'letter+1'. The present level is 0 and the backreference specifies +1. The capturing group still retains all its previous successful recursion levels. So the backreference can still match the b that the group captured during the first recursion. Now \b matches at the end of the string. abcdefzdcb was matched successfully.

You can take this as far as you like in this direction too. The regular expression \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+2'|z)|[a-z])\b matches abcdefzzedc. \b(?'word'(?'letter'[a-z])\g'word'(?:\k'letter+99'|z)|[a-z])\b matches abcdefzzzzzz.

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