Reading Three Regular Expression Operations

Alternation selects either pattern. Concatenation places matches one after another. Star repeats a pattern zero or more times.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace a short expression
  2. Keep implementation features separate
  3. Identify the grouping assumed by each operator
  4. Distinguish formal notation from a library's extended features

Trace a short expression

In formal notation \((a\mid b)c^*\) accepts a, ac, bcc, and similar words, but not abc. The first choice consumes a or b and the remainder consumes only copies of c. See Kleene star.

Keep implementation features separate

A formal expression describes a language. Some programming engines add operations with other semantics. Regular expressions and automata give the standard formal correspondence.[1]

Identify the grouping assumed by each operator

Expression a(b|c)*d accepts an a, then zero or more copies from b or c, then a d. Both ad and abccd qualify. Removing the parentheses can change which pieces the repetition operator covers. See Kleene star.

Middle blocks for abccd: b,c,c
Empty middle for ad
To match the complete word, all source symbols must be consumed

Distinguish formal notation from a library's extended features

Programming libraries can set flags and support operations beyond these formal ones. Test the intended match mode and grouping with a fixture exercising zero and multiple repetitions.

References

  1. Michael Sipser, Introduction to the Theory of Computation ↩