gpt4 book ai didi

regex - Perl 正则表达式/(\r\n|\r|\n)/

转载 作者:行者123 更新时间:2023-12-01 09:09:00 24 4
gpt4 key购买 nike

我想知道这种模棱两可的模式在 perl 中是如何解决的(更一般地说是所有使用 libpcre 的东西):

/(\r\n|\r|\n)/

当模式看到 \r\n 时会匹配一次还是两次?面对这种情况的规则是什么?

谢谢

最佳答案

它将匹配 \r\n 一次,因为 Perl 使用了一个正则表达式导向的引擎,它急切地评估交替。见 here .

You can easily find out whether the regex flavor you intend to use has a text-directed or regex-directed engine. If backreferences and/or lazy quantifiers are available, you can be certain the engine is regex-directed. You can do the test by applying the regex regex|regex not to the string regex not. If the resulting match is only regex, the engine is regex-directed. If the result is regex not, then it is text-directed. The reason behind this is that the regex-directed engine is "eager".

关于regex - Perl 正则表达式/(\r\n|\r|\n)/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3353762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com