正则表达式:数学方式与编程方式
考虑以下正则表达式:
- 7+
- (7)+
非常熟悉数学正则表达式理论的人是否同意这两个正则表达式在语义上相同?
Consider the following regular expressions:
- 7+
- (7)+
Does anyone that is very familiar with regular expression theory in Mathematics agree that the two regular expressions are semantically the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以编程方式(如由语言的正则表达式引擎计算),它仅在 捕获组 由此产生。
除此之外,它们是相同的。它就像写作
((7) + (1))
而不是7 + 1
。它们评估是相同的。 (是的,从数学上来说,常规语言不会评估任何东西)Programmatically (as in evaluated by the regular expression engine of a language) it only differs in the capturing groups resulting.
Other than that, they are the same. It is as writing
((7) + (1))
as opposed as7 + 1
. Theyevaluate toare the same. (Yeah, mathematically speaking, regular languages doesn't evaluate to anything)是的,这两个正则表达式是相同的,因为它们都识别相同的语言。事实上,它们的写法并不相同,这只是一个符号问题。
Yes, those two regular expressions are the same because they both recognize the same language. The fact that they are not written identically is just a notational issue.
它们描述的是同一种语言吗?是的。对于试图解释该语言的人来说,它们意味着同样的事情吗?不,第二个告诉我我应该对 7 更感兴趣。
Do they describe the same language? Yes. Do they mean the same thing to someone trying to interpret the language? No. The second one tells me that I should be more interested in the 7s.
第二个减少到第一个。您是否同意
和
以及
在语义上不同?
The second reduces to first. Do you agree that
and
and
are semantically different?
唯一的区别是括号将封闭的模式分配给一个组,以便您可以在评估后引用该小块。
The only difference is the parens assign the enclosed pattern to a group so you can reference that little piece after it's been evaluated.