📜  正则表达式

📅  最后修改于: 2020-11-26 10:12:00             🧑  作者: Mango


正则表达式可以如下递归定义-

  • ε是一个正则表达式,表示包含空字符串的语言。 (L(ε)= {ε})

  • φ是表示空语言的正则表达式。 (L(φ)= {})

  • x是一个正则表达式,其中L = {x}

  • 如果X是表示语言L(X)的正则表达式,而Y是表示语言L(Y)的正则表达式,则

    • X + Y是与语言L(X)∪L(Y)对应的正则表达式,其中L(X + Y)= L(X)∪L(Y)

    • X 。 Y是与语言L(X)相对应的正则表达式。 L(Y)其中L(XY)= L(X)。长(Y)

    • R *是对应于语言L(R *)的正则表达式,其中L(R *)=(L(R))*

  • 如果我们从1到5多次应用任何规则,它们就是正则表达式。

一些可再生能源的例子

Regular Expressions Regular Set
(0 + 10*) L = { 0, 1, 10, 100, 1000, 10000, … }
(0*10*) L = {1, 01, 10, 010, 0010, …}
(0 + ε)(1 + ε) L = {ε, 0, 1, 01}
(a+b)* Set of strings of a’s and b’s of any length including the null string. So L = { ε, a, b, aa , ab , bb , ba, aaa…….}
(a+b)*abb Set of strings of a’s and b’s ending with the string abb. So L = {abb, aabb, babb, aaabb, ababb, …………..}
(11)* Set consisting of even number of 1’s including empty string, So L= {ε, 11, 1111, 111111, ……….}
(aa)*(bb)*b Set of strings consisting of even number of a’s followed by odd number of b’s , so L = {b, aab, aabbb, aabbbbb, aaaab, aaaabbb, …………..}
(aa + ab + ba + bb)* String of a’s and b’s of even length can be obtained by concatenating any combination of the strings aa, ab, ba and bb including null, so L = {aa, ab, ba, bb, aaab, aaba, …………..}