我试图理解正则表达式:
你能提供与这种模式匹配的例子吗?
0+1 表示联合。这听起来像逻辑 OR,不是吗?我们应该在 0 还是 1 之间选择?
01 表示串联。这听起来很合逻辑,不是吗?我们应该一起使用01数字吗?
(0+1)* 表示迭代。我们可以迭代 0 或 1 n 次吗?000011110000是否匹配 (0+1)* 模式?
如果将其解释为正则表达式,则匹配包含以下内容的表达式
zero or more sequences of
(one or more zeros followed by a single one),
followed by a single one,
followed by zero or more sequences of
(one or more zeros followed by a single one)
Run Code Online (Sandbox Code Playgroud)
作为布尔代数表达式,如果删除星号,则计算结果为
(false OR true) AND true AND (false OR true)
Run Code Online (Sandbox Code Playgroud)
其评估为真。