PHP/PCRE 中对其他递归级别的反向引用

Backreferences to other recursion levels in PHP / PCRE

我试图在网上找到答案,但找不到。此页面的第三部分是否适用于 PHP / PCRE?

https://www.regular-expressions.info/recursebackref.html

"Backreferences to other recursion levels part"。我只对 PHP 感兴趣,所以如果这不适用于 PHP 语言(或者可能 JavaScript),这就是我需要知道的全部内容。

谢谢。

PCRE 不支持具有递归级别的反向引用,信息属于 Ruby Onigmo 正则表达式引擎。

参见Onigmo reference

\k<n+level>  \k'n+level'
\k<n-level>  \k'n-level'
\k<-n+level> \k'-n+level'
\k<-n-level> \k'-n-level'

\k<name+level> \k'name+level'
\k<name-level> \k'name-level'

Destine a group on the recursion level relative to the referring position.

ex 1.

  /\A(?<a>|.|(?:(?<b>.)\g<a>\k<b>))\z/.match("reee")
  /\A(?<a>|.|(?:(?<b>.)\g<a>\k<b+0>))\z/.match("reer")

  \k<b+0> refers to the (?<b>.) on the same recursion level with it.

看到一个Rubular demo

至于 PCRE,唯一允许的语法反向引用是

 \n              reference by number (can be ambiguous)
 \gn             reference by number
 \g{n}           reference by number
 \g{-n}          relative reference by number
 \k<name>        reference by name (Perl)
 \k'name'        reference by name (Perl)
 \g{name}        reference by name (Perl)
 \k{name}        reference by name (.NET)
 (?P=name)       reference by name (Python)