[英]Regular expression for a DFA that accepts the empty string as well as other strings
For the following DFA NFA 对于以下DFA NFA
I produced the RE 我制作了RE
(a + b)(ab)*
However, I then realised that my RE doesn't accept the empty string as it only accepts strings beginning with an a
or a b
, yet the DFA NFA also accepts the empty string as the initial state is an accepting state. 但是,然后我意识到我的RE不接受空字符串,因为它只接受以a
或b
开头的字符串,但是DFA NFA也接受空字符串,因为初始状态是接受状态。
What is a valid RE for this DFA NFA? 此DFA NFA的有效RE是什么? I would think something along the lines of 我会想一些类似的
Ø + (a + b)(ab).*
but I doubt this syntax is accepted. 但我怀疑这种语法是否被接受。
EDIT 编辑
I have also just realised that the example I have made is an NFA, but that is besides the point of the question. 我也刚刚意识到,我所举的例子是NFA,但这不是问题的重点。
(a + b)* would be the answer of what you mentioned in the question title. (a + b)*将是您在问题标题中提到的答案。 With an *, it means you can have empty string. 带*表示您可以有空字符串。 a+b means you can choose either a or b. a + b表示您可以选择a或b。 So finally you can choose a or b repeatedly. 所以最后您可以重复选择a或b。
How about the following expression? 下面的表达式如何?
^(|[ab](ab)*)$
This accepts either an empty string, or a sequence of none or more times ab
, preceded by an a
or b
. 它接受一个空字符串,或者一个无序或多次ab
的序列,后跟a
或b
。
But it depends on the exact regular expression dialect if this solves your problem. 但是,这能否解决您的问题取决于确切的正则表达式方言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.