1.3 REGULAR EXPRESSIONS (reglulegar segðir) Flashcards
What are regular expressions?
we can use the regular operations to build up expressions describing languages, which are called regular expressions. An example is:
(0∪1)0∗.
Σ∗ describes
the language consisting of all strings over that alphabet.
Σ∗1 is ?
the language that contains all strings that end in a 1.
Which operations are done first in regex?
The star operation is done first,
followed by concatenation,
and finally union,
unless parentheses change the usual order.
Formal definition of a regular expession
Say that R is a regular expression if R is
1. a for some a in the alphabet Σ,
2. ε,
3. ∅,
4. (R1 ∪ R2), where R1 and R2 are regular expressions,
5. (R1 ◦ R2), where R1 and R2 are regular expressions, or
6. (R1∗), where R1 is a regular expression.
Don’t confuse the regular expressions ε and ∅. What is the different?
The expression ε represents the language containing a single string—namely, the empty string—whereas ∅ represents the language that doesn’t contain any strings.
0∗10∗
{w| w contains a single 1}.
Σ∗1Σ∗
{w| w has at least one 1}.
Σ∗001Σ∗
{w| w contains the string 001 as a substring}.
1∗(01+)∗
{w| every 0 in w is followed by at least one 1}.
(ΣΣ)∗
{w| w is a string of even length}.
(ΣΣΣ)∗
{w| the length of w is a multiple of 3}.
01 ∪ 10
{01, 10}.
0Σ∗0 ∪ 1Σ∗1 ∪ 0 ∪ 1
{w| w starts and ends with the same symbol}.
(0∪ε)1∗
01∗ ∪1∗.
The expression 0 ∪ ε describes the language {0, ε}, so the concatenation operation adds either 0 or ε before every string in 1∗ .