gpt4 book ai didi

regex - 正则表达式(regex)真的是正则的吗?

转载 作者:行者123 更新时间:2023-12-04 14:41:47 24 4
gpt4 key购买 nike

我了解正则表达式是如何得名的,并且已经阅读了相关问题 ( Why are regular expressions called "regular" expressions? ),但我仍然想知道正则表达式是否总是规则的。

例如,反向引用如何是规则的?这是否不需要一些内存,因此不可能由有限状态自动机匹配/生成?

最佳答案

您引用的问题的答案中的链接(在维基百科中),与现代编程语言提供的许多正则表达式引擎相反,这些引擎增加了一些功能,可以识别经典正则表达式无法表达的语言。

所以我会说正则表达式的演变使它远离了表达正则语言的最初想法。

来自 Wikipedia article on regular expressions :

Many features found in virtually all modern regular expression libraries provide an expressive power that far exceeds the regular languages. For example, many implementations allow grouping subexpressions with parentheses and recalling the value they match in the same expression (backreferences). This means that, among other things, a pattern can match strings of repeated words like "papa" or "WikiWiki", called squares in formal language theory. The pattern for these strings is (.+)\1.

关于regex - 正则表达式(regex)真的是正则的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36283119/

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