简体   繁体   中英

Backreferences to other recursion levels in PHP / PCRE

I was trying to find the answer on the Net but I was not able to. Does the third section on this page applies to PHP / PCRE or not?

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

the "Backreferences to other recursion levels part". I am only interested in PHP, so if this does not apply to the PHP language (or possibly JavaScript), this is all that I need to know.

Thanks.

Backreferences with recursion level are not supported by PCRE, the information pertains to Ruby Onigmo regex engine.

See 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.

See a Rubular demo .

As for PCRE , the only syntax backreferences allow is

 \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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM