UNIHIVE

Study Hub UNIPORT CSC 396

CSC 396 · Automata theory, Computability and Formal Languages

Regular expressions and regular languages

Writing regular expressions, Kleene's theorem linking them to automata, closure properties, and regular expressions in real tools.

Our notes

2 min read

Regular expressions

Built from:

  • ∅, ε and single symbols (a),
  • union r + s (written r | s in tools),
  • concatenation rs,
  • star r*.

Precedence: star, then concatenation, then union.

Examples over {0, 1}

LanguageRegular expression
strings ending in 01(0 + 1)*01
strings containing 11(0 + 1)* 11 (0 + 1)*
even number of 1s0*(10*10*)*
strings of length 2(0 + 1)(0 + 1)
no two consecutive 1s(0 + 10)*(ε + 1)

Check the last one: 1010 = (10)(10) then ε ✓; 0110 contains 11, and no choice of pieces produces it ✓.

Kleene's theorem (1956)

A language is regular if and only if some regular expression describes it, if and only if some finite automaton accepts it. Expressions and automata describe exactly the same class of languages.

  • Expression to NFA: Thompson's construction builds small NFAs for symbols and joins them with ε-moves for union, concatenation and star.
  • DFA to expression: eliminate states one by one, labelling edges with expressions.

Closure properties

If L and M are regular, so are L ∪ M, LM, L*, the complement of L, L ∩ M and the reverse of L. These help prove languages regular (build from simpler ones) or not regular (see the pumping lemma).

Algebraic laws

r + s = s + r; (rs)t = r(st); εr = r; ∅r = ∅; (r*)* = r*; (r + s)* = (r*s*)*.

Regular expressions in practice

Text editors, grep, programming languages (Python's re module, JavaScript) and input validation use extended syntax:

  • [0-9] any digit, \d digit, . any character, + one or more, ? optional, {n} exactly n, ^ start, $ end.
  • A Nigerian mobile number written 080..., 081..., 070..., 090... with 11 digits: ^0[789][01]\d{8}$ (a simple check: it accepts 08031234567 and rejects 0803123456).

Some tools add features (back-references) that go beyond true regular languages.

Exams usually ask

  • Write regular expressions for described languages.
  • State Kleene's theorem; convert an expression to an NFA.
  • Use closure properties.

Common mistake

Writing 0*1*0* for "strings with no 11". It accepts 0110, which contains 11, and rejects 0101, which does not. Describe the pieces between the 1s instead, as in (0 + 10)*(ε + 1), and test several strings both ways.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

No reading links here yet

Our team adds free books, videos and practice for each topic, and opens every link before it goes up.

All CSC 396 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.