gpt4 book ai didi

python - 这种对正则表达式中备选方案的描述是错误的吗?

转载 作者:行者123 更新时间:2023-11-28 18:54:24 26 4
gpt4 key购买 nike

关于 PEG 的维基百科文章状态:

The fundamental difference between context-free grammars and parsing expression grammars is that the PEG's choice operator is ordered. If the first alternative succeeds, the second alternative is ignored. Thus ordered choice is not commutative, unlike unordered choice as in context-free grammars and regular expressions.

但是this question已经发现如果备选方案是彼此的子串;那么正则表达式不会根据unordered choice 运行。 wiki 的大部分内容都是正确的,但没有考虑到这种边缘情况。我的评估是否正确?

最佳答案

“正则表达式”!=“正则表达式”。后者纯粹而简单,只有理论计算机科学家和符号数学家才会感兴趣。

“有序选择”是正则表达式处理器的一个实现选项。

你说“如果备选方案是彼此的子串;那么正则表达式不会根据无序选择运行”。

一个更正确的说法是“一些正则表达式处理器对所有交替使用有序选择。当一个替代是另一个的前缀时,这会变得很明显。”

关于python - 这种对正则表达式中备选方案的描述是错误的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5906464/

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