Discrete MathematicsLanguages, Automata and Computability1 of 6
Languages, Automata and Computability · 1

Strings, Languages and Regular Expressions

We need a simple, exact way to describe which sequences of symbols follow a rule, even when there are infinitely many valid ones.

1

Alphabets, Strings and the Empty String

Before we can state a rule for valid sequences, we have to fix the set of symbols we are allowed to use and see how those symbols line up into strings.

Alphabets, Strings and the Empty String
password\htmlClass{lc-mute}{\text{password}}
a\text{a}
b\text{b}
c\text{c}
11
22
33
code\htmlClass{lc-mute}{\text{code}}
x\text{x}
==
x\text{x}
++
11
DNA\htmlClass{lc-mute}{\text{DNA}}
G\text{G}
A\text{A}
T\text{T}
T\text{T}
A\text{A}
C\text{C}
A\text{A}

We write a string by placing symbols from the alphabet side by side in order, and its length is the number of symbols in it:

Σ={0,1}⏟alphabet,w=0100⏟string of length ∣w∣=4,ε⏟empty string, ∣ε∣=0\displaystyle \begin{gathered} \underbrace{\Sigma = \{0, 1\}}_{\text{alphabet}}, \qquad \underbrace{w = 0100}_{\text{string of length } |w| = \counted{4}}, \\ \underbrace{\varepsilon}_{\text{empty string, } |\varepsilon| = \counted{0}} \end{gathered}

The symbol ε\varepsilon (you might also see it written as λ\lambda) is not a character inside Σ\Sigma; it is our name for the string with zero symbols. Because ε\varepsilon has no symbols, gluing it onto any string by concatenation leaves that string unchanged:

01⋅111=01111,01⋅ε=01\displaystyle \begin{aligned} \first{01} \cdot \second{111} &= \first{01}\second{111}, \\ \first{01} \cdot \varepsilon &= \first{01} \end{aligned}

An exponent on a string tells us how many copies of that string to glue together, not to multiply numbers:

03=000,02=00,01=0,00=ε\displaystyle \begin{aligned} 0^3 &= 000, \\ 0^2 &= 00, \\ 0^1 &= 0, \\ 0^0 &= \varepsilon \end{aligned}
2

Languages and the Empty Set Trap

Once we can form strings from an alphabet Σ\Sigma, we collect every possible finite string into an infinite set called Σ∗\wild{\Sigma^*}. A language is simply any subset of strings we choose from Σ∗\wild{\Sigma^*}.

Languages and the Empty Set Trap
Σ={0,1}\Sigma = \{0, 1\}
length 0\htmlClass{lc-mute}{\text{length}}\ \htmlClass{lc-green}{0}
ε\varepsilon
length 1\htmlClass{lc-mute}{\text{length}}\ \htmlClass{lc-green}{1}
00
11
length 2\htmlClass{lc-mute}{\text{length}}\ \htmlClass{lc-green}{2}
0000
0101
1010
1111
length 3\htmlClass{lc-mute}{\text{length}}\ \htmlClass{lc-green}{3}
000000
001001
010010
011011
100100
101101
110110
111111
…\dots
⋮\vdots

Listing Σ∗\wild{\Sigma^*} by length shows how the empty string ε\varepsilon sits at length 0\counted{0} before the strings of length 1\counted{1}, 2\counted{2}, and so on:

Σ∗={ε⏟length 0,  0,1⏟length 1,  00,01,10,11⏟length 2,  000,…,111⏟length 3,  … }\displaystyle \begin{aligned} \wild{\Sigma^*} = \{&\underbrace{\varepsilon}_{\text{length } \counted{0}},\; \underbrace{0, 1}_{\text{length } \counted{1}},\; \underbrace{00, 01, 10, 11}_{\text{length } \counted{2}},\; \\ &\underbrace{000, \dots, 111}_{\text{length } \counted{3}},\; \dots\} \end{aligned}

When a language has no strings, or only the empty string, the set braces make all the difference.

∅\emptyset
0 strings\htmlClass{lc-green}{0}\text{ strings}
{ε}\{\varepsilon\}
ε\varepsilon
1 string\htmlClass{lc-green}{1}\text{ string}
(of length 0)\text{(of length }\htmlClass{lc-green}{0}\text{)}
∅⏟empty language: 0 strings≠{ε}⏟1 string (of length 0)\displaystyle \underbrace{\emptyset}_{\text{empty language: } \counted{0} \text{ strings}} \neq \underbrace{\{\varepsilon\}}_{\counted{1} \text{ string (of length } \counted{0}\text{)}}
3

Operations on Languages

To build large or infinite languages from small ones, we combine sets of strings using union, concatenation, and the star operation.

Operations on Languages
A=\htmlClass{lc-blue}{A} =
0\htmlClass{lc-blue}{0}
11\htmlClass{lc-blue}{11}
B=\htmlClass{lc-pink}{B} =
a\htmlClass{lc-pink}{a}
b\htmlClass{lc-pink}{b}
Text solution
Combine sets with union (++ or ∣|)Collect every string that belongs to A={0,11}\first{A} = \{\first{0}, \first{11}\} or to B={a,b}\second{B} = \{\second{a}, \second{b}\} into a single language.
A∪B\displaystyle \first{A} \cup \second{B} =A+B\displaystyle = \first{A} + \second{B} ={0,11,a,b}\displaystyle = \{\first{0}, \first{11}, \second{a}, \second{b}\}
Pair strings in order for concatenation (AB\first{A}\second{B})Pick one string from A\first{A} followed by one string from B\second{B} in every possible combination.
AB\displaystyle \first{A}\second{B} ={0a,0b,11a,11b}\displaystyle = \{\first{0}\second{a}, \first{0}\second{b}, \first{11}\second{a}, \first{11}\second{b}\}
Make a fresh choice on each pick in A∗\first{A}^*Take the union of picking 0,1,2,…0, 1, 2, \dots strings from A={0,11}\first{A} = \{\first{0}, \first{11}\}, where A2\first{A}^2 chooses independently from A\first{A} on each pick rather than repeating the same string twice.
A0={ε}A1={0,11}A2={00,011,110,1111}A∗=A0∪A1∪A2∪⋯={ε,0,11,00,011,110,1111,… }\displaystyle \begin{aligned} \first{A}^0 &= \{\varepsilon\} \\ \first{A}^1 &= \{\first{0}, \first{11}\} \\ \first{A}^2 &= \{00, 011, 110, 1111\} \\ \first{A}^* &= \first{A}^0 \cup \first{A}^1 \cup \first{A}^2 \cup \cdots \\ &= \{\varepsilon, 0, 11, \\ &\qquad 00, 011, 110, 1111, \dots\} \end{aligned}
Concatenate and star {ε}\{\varepsilon\} and ∅\emptysetGluing ε\varepsilon changes nothing, gluing from ∅\emptyset gives nothing because there is no string to pick from ∅\emptyset, and picking 00 strings from ∅\emptyset gives ε\varepsilon.
L{ε}=L,L∅=∅,∅∗=∅0⏟{ε}∪∅1⏟∅∪∅2⏟∅∪⋯={ε}\displaystyle \begin{aligned} \first{L}\{\varepsilon\} &= \first{L}, \\ \first{L}\emptyset &= \emptyset, \\ \emptyset^* &= \underbrace{\emptyset^0}_{\{\varepsilon\}} \cup \underbrace{\emptyset^1}_{\emptyset} \cup \underbrace{\emptyset^2}_{\emptyset} \cup \cdots \\ &= \{\varepsilon\} \end{aligned}

See if you can use these rules to evaluate each language expression before flipping the card:

See how changing the strings in a set changes its products and powers, while pairing with the empty set always gives nothing and zero picks always leaves the empty string.
4

Regular Expressions and Order of Operations

Instead of writing out infinite sets of strings, we use a regular expression as a compact formula that builds a language from ∅\emptyset, ε\varepsilon, and single symbols in Σ\Sigma using ++, concatenation, and ∗*.

Regular Expressions and Order of Operations
or\text{or}
A+B\htmlClass{lc-blue}{A} + \htmlClass{lc-pink}{B}
glue\text{glue}
AB\htmlClass{lc-blue}{A}\htmlClass{lc-pink}{B}
repeat\text{repeat}
A∗\htmlClass{lc-blue}{A}^*
??
{0,01,011,0111,… }\{0, 01, 011, 0111, \dots\}

Just like algebra, regular expressions drop extra parentheses by following a fixed order of operations from highest priority to lowest:

R∗⏟1. star (like an exponent)⟶RS⏟2. glue (like multiplication)⟶R+S⏟3. or (like addition)\displaystyle \begin{aligned} &\underbrace{\first{R}^*}_{\text{1. star (like an exponent)}} \\ \longrightarrow \quad &\underbrace{\first{R}\second{S}}_{\text{2. glue (like multiplication)}} \\ \longrightarrow \quad &\underbrace{\first{R} + \second{S}}_{\text{3. or (like addition)}} \end{aligned}
Text solution
Apply the star to the piece right next to it firstIn 0+10∗0 + 10^*, the star only applies to the 00 right next to it, not 10\fails{10}.
0+1(0∗)\displaystyle 0 + 1(0^*)
Concatenate before taking the unionGlue 11 to 0∗0^* before splitting at ++, giving either a single 00 or a 11 followed by any number of 00s.
0+(1(0∗))⟶{0,1,10,100,1000,… }\displaystyle 0 + (1(0^*)) \longrightarrow \{0, 1, 10, 100, 1000, \dots\}
Put ++ inside (0+1)∗\wild{(0 + 1)^*} to make a fresh choice each timeIn 0∗+1∗0^* + 1^*, you choose 0∗0^* or 1∗1^* once at the start, whereas (0+1)∗\wild{(0 + 1)^*} lets you pick a fresh 00 or 11 on each repetition to build every binary string in Σ∗\wild{\Sigma^*}.
0∗+1∗⟶{ε,0,00,…,1,11,… },(0+1)∗⏟wildcard Σ∗⟶{ε,0,1,00,01,10,11,… }\displaystyle \begin{aligned} &0^* + 1^* \\ &\quad \longrightarrow \{\varepsilon, 0, 00, \dots, 1, 11, \dots\}, \\[4pt] &\underbrace{\wild{(0 + 1)^*}}_{\text{wildcard } \wild{\Sigma^*}} \\ &\quad \longrightarrow \{\varepsilon, 0, 1, 00, 01, 10, 11, \dots\} \end{aligned}

Check the order of operations and where the star sits on the card below:

A star only repeats what sits right to its left, so moving parentheses changes whether a string can repeat 0, stick to one symbol, or switch between 0 and 1 on every lap.
5

Writing Regular Expressions with Slots and Blanks

To turn a rule over Σ={0,1}\Sigma = \{0, 1\} into a regular expression, we put the required symbols into fixed slots first and then fill the blanks around them with whatever symbols are still allowed.

Writing Regular Expressions with Slots and Blanks
Σ={0,1}\Sigma = \{0, 1\}
starts with 0, ends with 11\text{starts with } 0\text{, ends with } 11
Text solution
Fix the ends and put the wildcard in the middleFor strings starting with 00 and ending with 1111, put 00 at the front and 1111 at the back with any binary string in between; when the front and back symbols match, as in starting and ending with 00, add the length-1\counted{1} string 00 with ++.
0⏟starts with 0(0+1)∗⏟any middle11⏟ends with 11,0(0+1)∗0⏟length ≥2+0⏟length 1\displaystyle \begin{gathered} \underbrace{0}_{\text{starts with } 0}\underbrace{\wild{(0 + 1)^*}}_{\text{any middle}}\underbrace{11}_{\text{ends with } 11}, \\ \underbrace{0\wild{(0 + 1)^*}0}_{\text{length } \ge \counted{2}} + \underbrace{0}_{\text{length } \counted{1}} \end{gathered}
Surround a required substring with wildcardsFor strings containing 0000, write 0000 once and allow any binary string before and after it.
(0+1)∗⏟before00(0+1)∗⏟after\displaystyle \underbrace{\wild{(0 + 1)^*}}_{\text{before}} 00 \underbrace{\wild{(0 + 1)^*}}_{\text{after}}
Fill blanks with 0∗0^* when 11s are countedFor strings with exactly two 11s, write the two 11s first and allow only 0∗0^* in the three surrounding blanks so the blanks never add a third 1\fails{1}.
0∗⏟only 0s10∗⏟only 0s10∗⏟only 0s\displaystyle \underbrace{0^*}_{\text{only } 0\text{s}} 1 \underbrace{0^*}_{\text{only } 0\text{s}} 1 \underbrace{0^*}_{\text{only } 0\text{s}}

Once you write an expression with required start and end slots, always check the shortest strings of length 0\counted{0} and 1\counted{1} (ε\varepsilon, 00, and 11), since two separate end slots force a string to have length at least 2\counted{2}.

6

Parity and Forbidden Substrings

Fixed slots work when we know the exact count of a symbol, but when a rule asks for an even count or forbids a substring like 00\fails{00}, we build the string out of repeatable blocks that keep the rule true on every repetition.

Parity and Forbidden Substrings
Σ={0,1}\Sigma = \{0, 1\}
even length0,2,4,6,8,…\text{even length}\qquad \htmlClass{lc-green}{0}, \htmlClass{lc-green}{2}, \htmlClass{lc-green}{4}, \htmlClass{lc-green}{6}, \htmlClass{lc-green}{8}, \dots
00
11
11
00
11
11
2\htmlClass{lc-green}{2}
4\htmlClass{lc-green}{4}
6\htmlClass{lc-green}{6}
Text solution
Repeat a two-symbol block for even or odd lengthGlue two (0+1)(0 + 1) slots into a length-2\counted{2} block and star it for even length, or glue one extra (0+1)\leftover{(0 + 1)} slot onto the end for odd length.
Even length:((0+1)(0+1))∗,Odd length:((0+1)(0+1))∗(0+1)\displaystyle \begin{aligned} &\text{Even length:} \\ &\quad \big((0 + 1)(0 + 1)\big)^*, \\[4pt] &\text{Odd length:} \\ &\quad \big((0 + 1)(0 + 1)\big)^*\leftover{(0 + 1)} \end{aligned}
Put 0∗0^* in front of a pair-of-11s loopFor an even number of 11s, start with 0∗0^* to cover strings with zero 11s (such as 000000) before repeating the two-11 block 10∗10∗10^*10^*.
0∗⏟zero 1s allowed(10∗10∗)∗⏟adds 1s in pairs\displaystyle \underbrace{0^*}_{\text{zero } 1\text{s allowed}}\underbrace{(10^*10^*)^*}_{\text{adds } 1\text{s in pairs}}
Pair each restricted symbol with the symbol that must follow itTo forbid 00\fails{00}, require every 00 before the end of the string to be followed right away by 11 as the block 01\safe{01}, and allow at most one 00 at the very end.
(1+01)∗⏟safe blocks(ε+0)⏟optional final 0\displaystyle \underbrace{(\safe{1} + \safe{01})^*}_{\text{safe blocks}}\underbrace{(\varepsilon + 0)}_{\text{optional final } 0}

Test this safe-block idea on the card below:

Every 0 before the end pairs with the 1 to its right, so two 0s in a row leave the first 0 without a 1.

Key concepts

In language operations, keep the empty language ∅\emptyset (0\counted{0} strings) separate from {ε}\{\varepsilon\} (1\counted{1} string of length 0\counted{0}): concatenating with {ε}\{\varepsilon\} changes nothing (L{ε}=L\first{L}\{\varepsilon\} = \first{L}), concatenating with ∅\emptyset gives the empty set (L∅=∅\first{L}\emptyset = \emptyset), and starring the empty set gives ∅∗={ε}\emptyset^* = \{\varepsilon\} because there is one way to pick 00 strings.

When reading or writing regular expressions over Σ={0,1}\Sigma = \{0, 1\}, star goes first, then concatenation, then ++, so 0+10∗0 + 10^* means 0+(1(0∗))0 + (1(0^*)). Putting the star outside parentheses in (0+1)∗\wild{(0 + 1)^*} gives a fresh choice on every repetition to build all of Σ∗\wild{\Sigma^*}, whereas 0∗+1∗0^* + 1^* chooses once at the start and only builds strings of all 00s or all 11s. Match the rule to the way you build the string:

Required start, end, or substring (no count limit)

Put the required pieces in place and fill the blanks with the wildcard (0+1)∗\wild{(0 + 1)^*}, as in (0+1)∗00(0+1)∗\wild{(0 + 1)^*}00\wild{(0 + 1)^*}, adding short length-1\counted{1} strings separately as in 0(0+1)∗0+00\wild{(0 + 1)^*}0 + 0.

Fixed count of 11s (do not use the wildcard (0+1)∗\wild{(0 + 1)^*} in blanks)

Place the required 11s in slots and fill the blanks with 0∗0^* only, as in 0∗10∗10∗0^*10^*10^* for exactly two 11s.

Even or odd count

Repeat a block that adds symbols or 11s in pairs: ((0+1)(0+1))∗\big((0 + 1)(0 + 1)\big)^* for even length, and 0∗(10∗10∗)∗0^*(10^*10^*)^* with a leading 0∗0^* for an even number of 11s.

Forbidden substring

Pair the restricted symbol with the symbol that must immediately follow it and handle the end of the string with an optional ending, as in (1+01)∗(ε+0)(\safe{1} + \safe{01})^*(\varepsilon + 0) for no 00\fails{00}.

7

Practice

1

Let Σ={0,1}\Sigma = \{0, 1\}, u=10\first{u} = \first{10}, and v=011\second{v} = \second{011}. Find the strings uv\first{u}\second{v}, u3\first{u}^3, and v0εu\second{v}^0\varepsilon \first{u}, and give the length of each.

What string do you get when any string is raised to the 00th power, and how many symbols does ε\varepsilon add when glued onto u\first{u}?

Gluing u\first{u} and v\second{v} gives uv=10011\first{u}\second{v} = \first{10}\second{011} with ∣uv∣=5|\first{u}\second{v}| = \counted{5}, and gluing three copies of u\first{u} gives u3=101010\first{u}^3 = \first{101010} with ∣u3∣=6|\first{u}^3| = \counted{6}. For v0εu\second{v}^0\varepsilon \first{u}, do not treat v0\second{v}^0 or ε\varepsilon as symbols of length 11 (which would give length 4\fails{4}) or write the symbol 00 for v0\second{v}^0 (which would give 010\fails{010} of length 3\fails{3}); both v0=ε\second{v}^0 = \varepsilon and ε\varepsilon are the empty string of length 0\counted{0}, so v0εu=ε⋅ε⋅10=10\second{v}^0\varepsilon \first{u} = \varepsilon \cdot \varepsilon \cdot \first{10} = \first{10} with ∣v0εu∣=2|\second{v}^0\varepsilon \first{u}| = \counted{2}.
2

Let L={0,11}\first{L} = \{\first{0}, \first{11}\}. List the elements of each language and state how many strings it contains: (a) L{ε}\first{L}\{\varepsilon\}, (b) L∅\first{L}\emptyset, (c) (L∅)∗(\first{L}\emptyset)^*, (d) L∪∅∗\first{L} \cup \emptyset^*.

Which of ∅\emptyset and {ε}\{\varepsilon\} acts like multiplying by 00 in concatenation, and what does picking 00 strings from an empty set give?

In (a), gluing ε\varepsilon onto each string in L\first{L} leaves it unchanged, and in (b), no pair can be formed with ∅\emptyset. In (c) and (d), watch out for the mistake of writing ∅∗=∅\emptyset^* = \fails{\emptyset} (which would give 0\fails{0} strings for (c) and 2\fails{2} strings for (d)): picking 00 strings from ∅\emptyset gives ε\varepsilon, so ∅∗={ε}\emptyset^* = \{\varepsilon\}.
(a) L{ε}={0,11}\first{L}\{\varepsilon\} = \{\first{0}, \first{11}\} (2\counted{2} strings); (b) L∅=∅\first{L}\emptyset = \emptyset (0\counted{0} strings); (c) (L∅)∗=∅∗={ε}(\first{L}\emptyset)^* = \emptyset^* = \{\varepsilon\} (1\counted{1} string); (d) L∪∅∗={ε,0,11}\first{L} \cup \emptyset^* = \{\varepsilon, \first{0}, \first{11}\} (3\counted{3} strings).
3

Let A={ε,0}\first{A} = \{\varepsilon, \first{0}\} and B={1,01}\second{B} = \{\second{1}, \second{01}\}. List all strings in AB\first{A}\second{B} and all strings in B2\second{B}^2, and state how many strings are in each language.

Write out all 2×2=42 \times 2 = \counted{4} glued pairs for each operation, then check whether two different pairs give the exact same string.

For AB\first{A}\second{B}, the four pairs are ε⋅1=1\varepsilon \cdot \second{1} = \second{1}, ε⋅01=01\varepsilon \cdot \second{01} = \second{01}, 0⋅1=01\first{0} \cdot \second{1} = \first{0}\second{1}, and 0⋅01=001\first{0} \cdot \second{01} = \first{0}\second{01}; do not count the duplicate 0101 twice to get 4\fails{4} strings. For B2\second{B}^2, do not just repeat the same string twice to get {11,0101}\{\fails{11}, \fails{0101}\} (2\fails{2} strings), because each pick from B\second{B} is a fresh choice.
AB={1,01,001}\first{A}\second{B} = \{1, 01, 001\} (3\counted{3} strings); B2={11,101,011,0101}\second{B}^2 = \{11, 101, 011, 0101\} (4\counted{4} strings).
4

Add parentheses to the regular expression 01∗+10∗01^* + 10^* to show the order of operations, and determine which of the strings ε\varepsilon, 00, 11, 1010, 011011, and 01100110 belong to its language.

Does each star apply to the two-symbol string to its left, or only to the single symbol right next to it?

Do not group the stars around two symbols as (01)∗+(10)∗\fails{(01)}^* + \fails{(10)}^* (which would wrongly include ε\varepsilon and leave out 00, 11, and 011011), and remember that ++ picks one side for the entire string so 01100110 cannot use both sides. Each star applies only to the symbol right next to it, then concatenation, then ++:
(0(1∗))+(1(0∗))(0(1^*)) + (1(0^*)), and the strings from the list in the language are 00, 11, 1010, and 011011.
5

Over Σ={0,1}\Sigma = \{0, 1\}, write a regular expression for all strings that start and end with the same symbol.

Split the rule into two cases with ++ (starts and ends with 00, or starts and ends with 11), and check whether strings of length 1\counted{1} are included.

Writing only 0(0+1)∗0+1(0+1)∗10\wild{(0 + 1)^*}0 + 1\wild{(0 + 1)^*}1 forces every string to have at least two symbols and misses the length-1\counted{1} strings 0\fails{0} and 1\fails{1}, each of which starts and ends with the same symbol. Including the length-1\counted{1} strings gives:
0(0+1)∗0+1(0+1)∗1+0+10\wild{(0 + 1)^*}0 + 1\wild{(0 + 1)^*}1 + 0 + 1.
6

Over Σ={0,1}\Sigma = \{0, 1\}, write a regular expression for all strings that contain at most two 11s.

"At most two 11s" means zero 11s, one 11, or two 11s. What is the only symbol allowed in the blanks around those 11s?

Do not fill the blanks with the wildcard (0+1)∗\wild{(0 + 1)^*}, as in (0+1)∗1(0+1)∗1(0+1)∗\wild{(0 + 1)^*}1\wild{(0 + 1)^*}1\wild{(0 + 1)^*}, which allows extra 11s in the blanks and describes strings with at least two 11s. Allowing only 0∗0^* in every blank across the cases of zero, one, or two 11s gives:
0∗+0∗10∗+0∗10∗10∗0^* + 0^*10^* + 0^*10^*10^* (or 0∗(ε+1)0∗(ε+1)0∗0^*(\varepsilon + 1)0^*(\varepsilon + 1)0^*).
7

Over Σ={0,1}\Sigma = \{0, 1\}, write a regular expression for all strings that have an odd number of 11s.

How do you combine our expression for an even number of 11s with one required 1\leftover{1}?

An odd number of 11s is one required 1\leftover{1} followed by an even number of additional 11s; be careful not to write 0∗1(10∗10∗)∗0^*\leftover{1}(10^*10^*)^* without a 0∗0^* after the first 1\leftover{1}, which would miss strings like 100\fails{100} where 00s follow the single 1\leftover{1}. Putting 0∗0^* on both sides of the first 1\leftover{1} before the pair loop gives:
0∗10∗(10∗10∗)∗0^*\leftover{1}0^*(10^*10^*)^* (or (0∗10∗1)∗0∗10∗(0^*10^*1)^*0^*\leftover{1}0^*).
8

Over Σ={0,1}\Sigma = \{0, 1\}, write a regular expression for all strings that do not contain 111\fails{111} (no three 11s in a row).

Before the end of the string, any 11 or 1111 must be followed right away by a 00. What are the three safe blocks that end in 00, and what can sit at the very end?

Every 11 or 1111 before the end of the string must be followed by 00, giving the repeatable blocks 0\safe{0}, 10\safe{10}, and 110\safe{110}. Do not stop at (0+10+110)∗(\safe{0} + \safe{10} + \safe{110})^*, which forces every non-empty string to end in 00 and misses valid strings ending in 1\fails{1} or 11\fails{11}. Allowing up to two 11s at the end gives:
(0+10+110)∗(ε+1+11)(\safe{0} + \safe{10} + \safe{110})^*(\varepsilon + 1 + 11).