0
$\begingroup$

I am trying to create a regular expression that will generate the following language under the {a,b,c} alphabet: all words that do not contain the substring "bbc"

I am having a really hard time understanding how to approach this question. I have done several other questions where a certain substring must be excluded, but this one really messes with my logic.

Thanks in advance

$\endgroup$
  • $\begingroup$ The key word you are looking is "complement", e.g., complement of a NFA, complement of a regular language. That should enable you to solve this in a pretty straightforward way. $\endgroup$ – D.W. Nov 5 '13 at 19:28
  • 1
    $\begingroup$ Design a NFA for $\{a,b,c\}^*bbc\{a,b,c\}^*$, make a DFA out of it, complement, read the expression from the automaton. This is in most cases the best way to solve this type of "pattern matching" problem. See other examples here. $\endgroup$ – Hendrik Jan Nov 5 '13 at 23:57
  • $\begingroup$ This question is similar to Regular expression for a string not containing a set of substrings $\endgroup$ – J.-E. Pin Nov 6 '13 at 4:42
2
$\begingroup$

Some things I learnt while learning to answer this type of question:

  1. Negation isn't easy to express. There are no shortcuts. The resulting expressions may be far more complex than the expression you would get if negation was a basic operator in the expression language - in which case you could write $\neg(.^*bbc.^*)$, where $.$ is a shortcut for $(a\cup\neg a)$
  2. Lacking $\neg$, the only way to say $\neg a$ for some symbol $a$ is to enumerate all other symbols: $\neg a = (b\cup c \cup d \cup \ldots)$. In Unix-like regular expressions, you can of course use [^a].
  3. In compound expressions, you can use left factorization. E.g. $\neg(bbc) = \epsilon \cup \neg b\neg(bc) = \epsilon \cup \neg b(\epsilon \cup \neg c) = \ldots$. The key insight is that this can be made to work with Kleene star expressions, too; I suggest you invent or look up the details yourself.
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.