简体   繁体   中英

Regular expression for a DFA that accepts the empty string as well as other strings

For the following DFA NFA

在此处输入图片说明

I produced the 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.

What is a valid RE for this DFA NFA? 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.

(a + b)* would be the answer of what you mentioned in the question title. With an *, it means you can have empty string. a+b means you can choose either a or b. So finally you can choose a or b repeatedly.

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 .

But it depends on the exact regular expression dialect if this solves your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM