Regular Expression,通常被译为“正则表达式”,何为“正则”?
看看WIKI的定义:
https://en.wikipedia.org/wiki/Regular_expression
A sequence of characters that define a search pattern, usually such patterns are used by string searching algorithms for “find” or “find and replace” operations on string or for input validation
The phrase regular expressions, and consequently, regexes, is often used to mean the specific, standard textual syntax (distinct from the mathematical notation described below) for representing patterns for matching text.
Each character in a regular expression (that is, each character in the string describing its pattern) is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.
从上面的文字可以看出,Regular Expression实际就是定义了一种“模式”,该模式用于搜索字符串。这个“模式”由字符集组成,其中的每一个字符,要么是“”有特殊含义的“元”字符(metacharacter),要么是有字面意义的常规字符(regular character that has a literal meaning)。
因此,学习和理解Regular Expression,首先必须抛弃“正则”这个概念,将其理解为“规范化表达式”更好一些,更容易理解。