来自 perlre 的文档:
然而,如果第二个捕获组有一个量词符号,该模式将永远不匹配:If the "(*ACCEPT)" is inside of capturing groups then the groups are marked as ended at the point at which the "(*ACCEPT)" was encountered. For instance:
'AB' =~ /(A (A|B(*ACCEPT)|C) D)(E)/x;
will match, and $1 will be "AB" and $2 will be "B" ...
'AB' =~ /(A (A|B(*ACCEPT)|C)+ D)(E)/x or die "No match"; #dies
^
为什么会这样呢?将 + 替换为 * 或 {0,99} 并没有任何区别。任何一个包含(*ACCEPT)
的捕获组上加量词似乎都会阻止 *ACCEPT 的工作。非常感谢您的帮助。
ABDE
! - ikegami