Hello!

A simple task, but I can not figure it out.

Построить регулярные выражения, задающих множество всех таких слов над словарем E = {a, b, c}, в которых за символом b: 1) обязательно следует символ c; 2) не может находиться символ c.

First made: (a|c|bc)+

For the second: (?(?<=b)(a|b)|.)+

But the task is complicated by the fact that it is impossible to use the backward / forward look-up and conditional search, that is, the second task was performed incorrectly.

Thanks a lot in advance!

ps. You can test on:

 abc acb bac bca cab cba cabcabcbacbcaaaccbbaaccacbac 

Answer: c*(cc|ac*|b|a)*[ab]*

Not sure that the optimal and absolutely correct, but the test examples passed.

  • Are you sure that you completed the first task correctly? If yes, then by analogy the 2nd: regex101.com/r/bT0lO8 - MDJHD
  • @MDJHD, the first is true. In your version, the error is that just b also a valid option. Like ab . We need to somehow push separately b , but so that bc unacceptable .. - Veikedo
  • And your teacher told you that the first is right with you? I just see the answer to the first task with such regex101.com/r/qQ2fZ6 , and you’re just a match for the characters, and the task contains the words - MDJHD
  • But I don’t deny that I understand the task definition itself - MDJHD
  • @MDJHD, individual characters are also words, but if the character b is found, then it should not be c . That is, for example, abc should be ab and separately c - Veikedo

1 answer 1

And then the second is something like this: http://regex101.com/r/iJ3eP9

  • Counterexample bbc - dzhioev