简体   繁体   中英

What does the “+0” mean in the regexp \k<name+0>?

I'm new to Regular Expressions in Ruby, and I can't seem to find any solid documentation on what \\k<name+0> means. It's the +0 part that I'm not getting.

Here's an example - this Regexp matches palindromes:

\A(?<p>(?:(?<l>\w)\g<p>\k<l+0>|\w))\z

When I remove the +0 in \\k<l+0> it no longer matches correctly.
My tests:

>> /\A(?<p>(?:(?<l>\w)\g<p>\k<l+0>|\w))\z/.match "aabbcdcbbaa" 
#=> #<MatchData "aabbcdcbbaa" p:"aabbcdcbbaa" l:"c">

>> /\A(?<p>(?:(?<l>\w)\g<p>\k<l>|\w))\z/.match "aabbcdcbbaa" 
#=> nil

All I've done is remove the +0 . I haven't yet found any documentation or example of this, can anyone point me in the right direction?

The \\k<l+0> works together with the (?<l>\\w)

The match of (?<l>\\w) is stored in the capturing group named 'l'

\\k<l+0> Matches the same text that was matched by the named capturing group 'l' when it was at the same recursion level as this backreference is now

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