所以我一直在寻找 PCRE 的完整备忘单(仍然没有找到,如果你能给我看一个,我会加分,我还没有找到一个同时包含\K 和\G 的)并且我偶然发现this old one .
现在我熟悉了环视断言,例如 (?<!somestuff)
或(?=otherstuff)
但我没有遇到过这个结构(来自链接到文章):
(?>…) zero-width independend[sic] subexpression
有人可以解释一下它的作用以及何时使用它吗?
另外可以向我指出包含 PCRE 中所有特殊符号的文档吗? ruby's docs甚至没有涵盖他们在正则表达式中拥有的所有功能:
[1] pry(main)> /hello\Kworld/.match("helloworld")
=> #<MatchData "world">
最佳答案
(?>...)
是一个原子组:
An atomic group is a group that, when the regex engine exits from it, automatically throws away all backtracking positions remembered by any tokens inside the group. Atomic groups are non-capturing.
而且,正如 Tim 指出的那样,原子组不是零宽度。
所有PCRE构建体的真实列表:http://www.pcre.org/pcre.txt
关于regex - 正则表达式中什么是零宽度独立子表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629518/