gpt4 book ai didi

java - 贪心量词

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

我在阅读 K.Sierra 时发现了以下句子:

The greedy quantifier does in fact read the entire source data, and then it works backward (from the right) until it finds the rightmost match. At that point, it includes everything from earlier in the source data up to and including the data that is part of the rightmost match.

现在,假设我们有如下来源:

"proj3.txt,proj1sched.pdf,proj1,proj2,proj1.java"

和模式:proj1([^,])*

为什么它与全文不匹配?由于贪婪,它应该匹配最右边的“proj1.java”,并且返回的匹配应该是最右边匹配之前的整个源?相反,它返回:

proj1sched.pdf
proj1
proj1.java

最佳答案

why doesn't it match the whole text?

因为您声明它必须以 proj1 开头

Being greedy it should have match the rightmost "proj1.java"

正确。

and the returned match should have been the entire source before the right most match?

不知道你为什么会这么想,或者为什么这会有用。如果您想要的话,您可以只执行 .*proj1.*

关于java - 贪心量词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17201398/

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