# A little help with regular expressions [duplicate]

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.

• 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.
– D.W.
Nov 5, 2013 at 19:28
• 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. Nov 5, 2013 at 23:57
• This question is similar to Regular expression for a string not containing a set of substrings Nov 6, 2013 at 4:42

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.