Regular Expressions & Kleene's Theorem

concatenation in a regular expression

When you write two patterns one after another, you are saying 'first match this, then match that, with no gap between'. This is concatenation, the regular-expression way of gluing patterns end to end. It is the operation you use whenever order matters, like an area code followed by a phone number.

If R and S are regular expressions, writing them side by side as RS (sometimes R·S) denotes the language of every string you can form by taking a string from L(R) and immediately following it with a string from L(S). Formally L(RS) = { uv : u ∈ L(R) and v ∈ L(S) }, where uv means string u followed by string v, and ∈ means 'is a member of'. For example, over {a, b}, the expression (a+b)(a+b) denotes all strings of length exactly 2: { aa, ab, ba, bb }. Concatenation has no written operator; juxtaposition is the operator.

Concatenation is associative (RS)T denotes the same language as R(ST), so we drop the parentheses, but it is not commutative: ab and ba are different strings, so RS and SR generally differ. The empty-string atom ε is its identity: Rε and εR both denote the same language as R. The empty set ∅ is an annihilator: R∅ and ∅R both denote ∅, because if either side offers no strings, there is nothing to glue.

The expression ab*c denotes one a, then zero or more b's, then one c: ac, abc, abbc, abbbc, and so on. Read it left to right as 'an a, followed by some b's, followed by a c'.

Side-by-side patterns must be matched in order.

Concatenation is not commutative: RS and SR usually denote different languages, because string order matters (ab is not ba). Beginners sometimes treat the two as interchangeable.

Also called
串聯接續運算