与正则表达式相关的混乱

use*_*790 1 regex regular-language

我对正则表达式有这种困惑.如果有两套 A及B再

是(AB)* = A*B*吗?

Gri*_*han 5

在正则表达式的背景下:是(AB)*= A*B*?

 No, (AB)* is not equals to A*B*
Run Code Online (Sandbox Code Playgroud)

(AB)* means ABABABABAB......AB AB序列(任意数量的时间).
A*B* means AAAA.....BBB......任意数量的A,后跟任意数量的B.在B之后,A不能出现.

路口-包括两个{ NULL string, AB }仅


例:

假设: A = xy和 B = z

  (AB)* = xyzxyz.....xyz  
  A*B*  =  xyxyxyxy....zzzz....z
Run Code Online (Sandbox Code Playgroud)

交叉口 - 两者都包括在内{ NULL string, xyz}.


例:

假设 -

  A = {a, b},  
  B = {c, d}  
Run Code Online (Sandbox Code Playgroud)

然后,

(AB)* =  ((a + b)(c + d))* , Its language  
L =  { ac, ab, acbd, acac, .....}   
Run Code Online (Sandbox Code Playgroud)

注意:此语言中的所有字符串都是均匀的!

和

A*B*  =   (a + b)* (c + d)* , Its language     
  L = { a, b, c, d, ac, ad, bc, bd, acbd, addb,.........}   
Run Code Online (Sandbox Code Playgroud)

注意:还包含奇数长度的字符串.