*61*

# Regular Expression

- The language accepted by finite automata can be easily described by simple expressions called Regular Expressions. It is the most effective way to represent any language.
- The languages accepted by some regular expression are referred to as Regular languages.
- A regular expression can also be described as a sequence of pattern that defines a string.
- Regular expressions are used to match character combinations in strings. String searching algorithm used this pattern to find the operations on a string.

**For instance:**

In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx, xxxx, â€¦..}

In a regular expression, x^{+} means one or more occurrence of x. It can generate {x, xx, xxx, xxxx, â€¦..}

## Operations on Regular Language

The various operations on regular language are:

**Union:** If L and M are two regular languages then their union L U M is also a union.

**Intersection:** If L and M are two regular languages then their intersection is also an intersection.

**Kleen closure:** If L is a regular language then its Kleen closure L1* will also be a regular language.

### Example 1:

Write the regular expression for the language accepting all combinations of aâ€™s, over the set âˆ‘ = {a}

**Solution:**

All combinations of aâ€™s means a may be zero, single, double and so on. If a is appearing zero times, that means a null string. That is we expect the set of {Îµ, a, aa, aaa, â€¦.}. So we give a regular expression for this as:

That is Kleen closure of a.

### Example 2:

Write the regular expression for the language accepting all combinations of aâ€™s except the null string, over the set âˆ‘ = {a}

**Solution:**

The regular expression has to be built for the language

This set indicates that there is no null string. So we can denote regular expression as:

R = a^{+}

### Example 3:

Write the regular expression for the language accepting all the string containing any number of aâ€™s and bâ€™s.

**Solution:**

The regular expression will be:

This will give the set as L = {Îµ, a, aa, b, bb, ab, ba, aba, bab, â€¦..}, any combination of a and b.

The (a + b)* shows any combination with a and b even a null string.