简体   繁体   English

regexp \ k <name + 0>中的“+0”是什么意思?

[英]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. 我是Ruby中的正则表达式的新手,我似乎无法找到关于\\k<name+0>含义的任何可靠文档。 It's the +0 part that I'm not getting. 这是我没有得到的+0部分。

Here's an example - this Regexp matches palindromes: 这是一个例子 - 这个Regexp匹配回文:

\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. 当我删除\\k<l+0>中的+0 ,它不再正确匹配。
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 . 我所做的就是删除+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) \\k<l+0>(?<l>\\w)一起使用

The match of (?<l>\\w) is stored in the capturing group named 'l' (?<l>\\w)的匹配存储在名为'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 \\k<l+0>匹配指定捕获组'l'匹配的相同文本,当它处于相同的递归级别时,此反向引用现在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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