Reading regular expressions
A regular expression describes a language. Star, concatenation and union are the three basic operations.
Rules
- a* : any number of a, including none
- a+ : at least one a
- a|b : a or b
- Star binds tighter than concatenation, concatenation tighter than union
Your turn
Three problems on this topic. The software checks your answer exactly.
- 1 · Reading regular expressions
- 2
- 3
Which word belongs to the language of the regular expression?
(ab)*
Word
Worked example
Which word belongs to the language of the regular expression?
(ab)*
Worked solution
- 1ab matches (ab)*.
- 2aaaaab does not match.
- 3b does not match.
- 4bbaaba does not match.
Typical mistake: The star applies only to the symbol or bracket directly before it: ab* is not (ab)*.
Common questions
Are ab* and (ab)* the same?
No. ab* is one a followed by any number of b, (ab)* repeats the pair ab.
