Ruby Question

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

means. It's the
part that I'm not getting.

Here's an example - this Regexp matches palindromes:


When I remove the
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
. I haven't yet found any documentation or example of this, can anyone point me in the right direction?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download