0

The alphabets of a regular language are ∑={a,b,c}

I need create regular expression for:

a.) Accepts strings that do not have two 'b' characters next to each other. example: aabccbaaccb <- allowed aabccbaaccbb <- not allowed

b.) Accepts strings with at least one character 'a' between two characters 'b'. example: babaaaaaab <- allowed babaaaaaabcb <- not allowed

Created regular expression need to be ready for that it can be tested with JFLAP.

Here is what Regular Expression I have already try to create

  • 1
    From [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask): "_**DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question_" – Ted Lyngmo Feb 21 '23 at 18:13
  • It is confusion that in point (a) you say that `aabccbaaccb` is allowed, but then it is not allowed by (b). So in the end it is not allowed. – trincot Feb 21 '23 at 21:40
  • Sorry if I expressed it unclearly. I need to construct two different regular expressions. Sections A and B have different requirements for forming a regular expression. – Henrik Eronen Feb 21 '23 at 23:55

2 Answers2

0

I think something like this would work:

^[ac]*(?:b$|bc*$|bc*a[ac]*)*$

In testing, it only matches strings where any pair of bs are separated by at least one a, just as the prompt describes.

Dillon Davis
  • 6,679
  • 2
  • 15
  • 37
0

For task A:

(a+c+ba+bc)*(b+!)

(For some odd reason JFLAP uses ! to represent the empty string, i.e. ϵ)

For task B:

(a+c+bc*a)*(bc*+!)
trincot
  • 317,000
  • 35
  • 244
  • 286
  • Do you mean with these I can solve task 'a' or task 'b'. I mean I have two separate problems to solve. – Henrik Eronen Feb 22 '23 at 00:07
  • The question mentioned "regular expression" in singular. You seem to be looking for two regular expressions. Also, the `regex` tag is maybe not what you intended, as that is a syntax with different symbols than you seem to use in the screenshot. See update of this answer. Not sure if you expect ϵ symbol for saying "don't consume any input". In regex syntax this is denoted with a `?` making a symbol optional. – trincot Feb 22 '23 at 07:38
  • Yes I have been looking for two regular expressions. Sorry for that, my expression in English is not so good. – Henrik Eronen Feb 23 '23 at 08:15
  • OK, did you have a chance to look at the regular expressions I proposed? – trincot Feb 23 '23 at 08:19