正则表达式中的regular是什么意思?

时间:2021-04-06 01:58:47

What does the "regular" in the phrase "regular expression" mean?

“正则表达式”中的“regular”是什么意思?

I have heard that regexes were regular at one time, but no more

我听说regex曾经是常规的,但现在已经不是了

4 个解决方案

#1


11  

The regular in regular expression comes from that it matches a regular language.

正则表达式中的正则表达式来自于它与正则语言相匹配。

The concept of regular expressions used in formal language theory is quite different from what engines like PCRE call regular expressions. PCRE and other similar engines have features like lookahead, conditionals and recursion, which make them able to match non-regular languages.

在形式语言理论中使用的正则表达式的概念与PCRE这样的引擎所称的正则表达式是完全不同的。PCRE和其他类似的引擎都有类似的功能,比如前瞻、条件和递归,这使得它们能够匹配非规则语言。

#2


4  

It comes from regular language. This is part of formal language theory. Check out the Chomsky hierarchy for other formal languages.

它来自于普通的语言。这是形式语言理论的一部分。查看乔姆斯基层次结构的其他正式语言。

#3


1  

It's signifying that it's a regular language.

这意味着它是一种常规语言。

Regexes are still popular. Some people frown on them but they remain a quick and easy (if you know how to use them) way of matching certain types of strings. The alternative is often a good few lines of code looping through strings and extracting the bits that you need which is much nastier!

regex仍受欢迎。有些人不喜欢他们,但他们仍然是一个快速和容易(如果你知道如何使用他们)的方式匹配某些类型的字符串。另一种选择通常是用几行代码在字符串中循环,并提取您需要的位,这是非常糟糕的!

I still use them on a regular (pun fully intended) basis, to give you a use case I used one the other day to match lines of guitar chords as oppose to lyrics. They're also commonly used for things like basic validation of email addresses and the like.

我仍然经常使用它们(双关语),给你一个我前几天用过的用例来匹配吉他和弦的线条,而不是歌词。它们通常也被用于诸如电子邮件地址之类的基本验证。

They're certainly not dead.

他们当然不是死了。

#4


1  

I think it comes from the term for the class of grammars that regular expressions describe: regular grammars (or "regular" languages). Where that term comes from is likely answered by a trip to Wikipedia.

我认为它来自于正则表达式所描述的语法类:正则语法(或“正则”语言)。这个词的来源很可能是*。

Modern regex engines that implement all those fancy look-ahead, pattern re-match, and subexpression counting features, well, those are recognizing a class of grammar that's a superset of regular grammars. "Classical" regular expressions correspond in mechanical ways to theoretical machines called "finite automata". That's a really fun subject in and of itself.

现代的regex引擎实现了所有这些花哨的外观,模式重匹配,以及子表达式的计数功能,这些都是识别一种语法,这是一种常规语法的超集。“经典”正则表达式以机械的方式对应于被称为“有限自动机”的理论机器。这是一个很有趣的话题。

#1


11  

The regular in regular expression comes from that it matches a regular language.

正则表达式中的正则表达式来自于它与正则语言相匹配。

The concept of regular expressions used in formal language theory is quite different from what engines like PCRE call regular expressions. PCRE and other similar engines have features like lookahead, conditionals and recursion, which make them able to match non-regular languages.

在形式语言理论中使用的正则表达式的概念与PCRE这样的引擎所称的正则表达式是完全不同的。PCRE和其他类似的引擎都有类似的功能,比如前瞻、条件和递归,这使得它们能够匹配非规则语言。

#2


4  

It comes from regular language. This is part of formal language theory. Check out the Chomsky hierarchy for other formal languages.

它来自于普通的语言。这是形式语言理论的一部分。查看乔姆斯基层次结构的其他正式语言。

#3


1  

It's signifying that it's a regular language.

这意味着它是一种常规语言。

Regexes are still popular. Some people frown on them but they remain a quick and easy (if you know how to use them) way of matching certain types of strings. The alternative is often a good few lines of code looping through strings and extracting the bits that you need which is much nastier!

regex仍受欢迎。有些人不喜欢他们,但他们仍然是一个快速和容易(如果你知道如何使用他们)的方式匹配某些类型的字符串。另一种选择通常是用几行代码在字符串中循环,并提取您需要的位,这是非常糟糕的!

I still use them on a regular (pun fully intended) basis, to give you a use case I used one the other day to match lines of guitar chords as oppose to lyrics. They're also commonly used for things like basic validation of email addresses and the like.

我仍然经常使用它们(双关语),给你一个我前几天用过的用例来匹配吉他和弦的线条,而不是歌词。它们通常也被用于诸如电子邮件地址之类的基本验证。

They're certainly not dead.

他们当然不是死了。

#4


1  

I think it comes from the term for the class of grammars that regular expressions describe: regular grammars (or "regular" languages). Where that term comes from is likely answered by a trip to Wikipedia.

我认为它来自于正则表达式所描述的语法类:正则语法(或“正则”语言)。这个词的来源很可能是*。

Modern regex engines that implement all those fancy look-ahead, pattern re-match, and subexpression counting features, well, those are recognizing a class of grammar that's a superset of regular grammars. "Classical" regular expressions correspond in mechanical ways to theoretical machines called "finite automata". That's a really fun subject in and of itself.

现代的regex引擎实现了所有这些花哨的外观,模式重匹配,以及子表达式的计数功能,这些都是识别一种语法,这是一种常规语法的超集。“经典”正则表达式以机械的方式对应于被称为“有限自动机”的理论机器。这是一个很有趣的话题。