正则表达式中对替代项的这种描述是错误的吗?

2024-05-14 13:44:25 发布

您现在位置:Python中文网/ 问答频道 /正文

维基百科关于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在大多数情况下是正确的,但不考虑此边缘条件。我的评估正确吗?你知道吗


Tags: andthefreeiscontext文章orderedchoice
1条回答
网友
1楼 · 发布于 2024-05-14 13:44:25

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

“有序选择”是regex处理器的一个实现选项。你知道吗

你说“如果备选方案是彼此的子字符串,那么正则表达式就不会按照无序的选择来运行”。你知道吗

一个更正确的说法是“一些正则表达式处理器对所有替换使用有序选择。当一个备选方案是另一个的前缀时,这一点就很明显了。”

相关问题 更多 >

    热门问题