Revision Notes
OxfordAQA A-Level Computer Science (9645): Regular expressions and regular languages – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.13.2: metacharacters, character classes, converting between regular expressions and FSMs, and a self-test.
- Subject
- Computer Science
- Level
- A LEVEL
- Topic
- Topic 13 – Theory of computation
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to OxfordAQA A Level Computer Science (9645), 2024-onwards. Official specification .
Syllabus page (what it covers and how it is assessed): OxfordAQA A Level Computer Science.
Syllabus points this page covers
9645 (A Level)
- 3.13.2 Regular expressions and regular languages
This page covers 1 of the 5 subtopics in topic 13, Theory of computation.
Found an error? Report a correction.
Need help with this topic? Request a free trial class for A Level Computer Science (9645).
These notes condense sub-topic 3.13.2 Regular expressions and regular languages of OxfordAQA International AS and A-level Computer Science (9645), Version 1.1 (International A-level content in topic 3.13, examined in Unit 4). For worked conversions, see the regular expressions study guide, then practise with the regular expressions practice questions.
What the specification requires
- Form and use simple regular expressions for string matching.
- Know the metacharacters
*,+,?,|and( ). - Use character classes, such as
[CH]and[A-Z]. - Describe the relationship between regular expressions and FSMs.
- Write a regular expression for the language of a given FSM.
- Design an FSM for the language of a given regular expression.
- Know what a regular language is.
Any other metacharacter in an exam question is explained in the question.
Key terms
| Term | Meaning |
|---|---|
| Regular expression | A pattern that describes a set of strings |
| Match | A string that belongs to the set the expression describes |
| Metacharacter | A symbol with a special meaning in an expression |
| Character class | Square brackets matching one character from a set or range |
| Regular language | A language that can be represented by a regular expression |
| FSM | A finite state machine that accepts or rejects strings |
Metacharacters
| Symbol | Meaning | Example | Matches | Rejects |
|---|---|---|---|---|
* |
0 or more | zu*m |
zm, zuum | zam |
+ |
1 or more | zu+m |
zum, zuum | zm |
? |
0 or 1 | colou?r |
color, colour | colouur |
| |
or | (sun|moon)light |
sunlight, moonlight | light |
( ) |
group | (ab)+ |
ab, abab | aba |
[ ] |
one character from a set | [CH]at |
Cat, Hat | Bat, CHat |
[A-Z] |
one character in the range | [A-Z][a-z]* |
Hello, H | hello, HELLO |
A repetition symbol applies to the single character, group or class just before it.
Building expressions step by step
| Description | Expression | Check |
|---|---|---|
| One or two capitals then one or two digits | [A-Z][A-Z]?[0-9][0-9]? |
A1, AB12 match; AB and A123 do not |
| Starts with a, any b or c, ends in d | a(b|c)*d |
ad, abccbd match; add does not |
| One or more pairs ab or ba | (ab|ba)+ |
abba matches; aba does not |
| Ends in 01 | (0|1)*01 |
1101 matches; 10 does not |
| x, optional y, any z | x+y?z* |
xxzz matches; y and xyy do not |
Regular languages and FSMs
- A language is regular if it can be represented by a regular expression.
- Any regular language can be recognised by an FSM.
- A regular expression can be written for the language recognised by any FSM.
- Regular expressions and FSMs are equivalent ways to define a regular language.
Converting from an FSM to an expression
Even number of 1s (start state S0 is accepting):
| State | Input 0 | Input 1 |
|---|---|---|
| S0 | S0 | S1 |
| S1 | S1 | S0 |
Each trip S0 to S1 and back is 10*1. The language is 0*(10*10*)*. It matches the empty string, 0, 11, 1010 and 10001, and rejects 111.
Converting from an expression to an FSM
For a(b|c)*d over a, b, c and d:
| State | a | b | c | d |
|---|---|---|---|---|
| S0 (start) | S1 | S3 | S3 | S3 |
| S1 | S3 | S1 | S1 | S2 |
| S2 (accepting) | S3 | S3 | S3 | S3 |
| S3 (trap) | S3 | S3 | S3 | S3 |
Method: read the expression left to right and add one state for each stage. Loops come from * and +, extra arcs come from |, a skip comes from ?, and everything else goes to a trap state.
For (0|1)*01 the machine needs three states: no progress (start), last symbol 0, and last two symbols 01 (accepting).
Limits
An FSM has finitely many states, so it cannot count without limit. No regular expression can describe “n symbols a followed by n symbols b”. Backus-Naur Form can.
Pattern-building checklist
- List the characters that must appear and in what order.
- For each position decide: exactly one (write it or a class), optional (
?), one or more (+), zero or more (*) or a choice (|in brackets). - Group anything repeated or chosen with
( ). - Test the shortest string you expect to match, one longer string and one that must fail.
Example: “a capital letter, then one or more digits, then an optional letter A or B” becomes [A-Z][0-9]+[AB]?. It matches K7, K72B and M105; it rejects 7K, K and K7C.
Exam traps
+is not optional. Use?for zero or one.- Brackets.
ab*and(ab)*are different. - Classes match one character.
[CH]atdoes not match CHat. *allows zero, so the empty string can match.- Alternation scope. Group the options:
(sun|moon)light. - Trap states. Mention them when you design an FSM.
- All three links. A full definition mentions expressions, FSMs and the word “regular”.
Quick self-test
- What does
?mean? - Does
ab*matcha? - Does
(ab)*matchaba? - What does
[A-Z]match? - Write an expression for “cat” or “cot”.
- Write an expression for one or more digits.
- Does
colou?rmatchcolr? - Does
x+y?z*matchxz? - What type of language can be recognised by an FSM?
- What state is used to reject strings that have gone wrong?
- Is
(0|1)*01matched by10101? - Why can no regular expression describe equal numbers of a then b?
Answers
- Zero or one repetition (the previous item is optional).
- Yes: an
afollowed by zerobcharacters. - No: after one
ab, the remainingacannot be matched. - Any single character from A to Z inclusive.
c(a|o)torc[ao]t[0-9]+- No: the letters
ouare missing, and only theuis optional. - Yes: x, no y, one z.
- A regular language.
- A trap state.
- Yes: it ends in 01.
- It needs unlimited counting, but an FSM has only a finite number of states.
- Regular expressions study guide
- Regular expressions practice questions
- Finite state machines revision notes
Official syllabus
OxfordAQA International AS and A-level Computer Science (9645) specification, Version 1.1, for International AS exams May/June 2025 onwards and International A-level exams May/June 2026 onwards: sub-topic 3.13.2 Regular expressions and regular languages.
Related resources
-
Study guides
OxfordAQA A-Level Computer Science (9645): Turing machines
OxfordAQA 9645 sub-topic 3.13.3 in depth: Turing machine parts, transition functions and diagrams, hand-tracing four machines, and the Universal Turing machine.
Computer Science · OxfordAQA · A Level
Read guide -
Practice questions
OxfordAQA A-Level Computer Science (9645): Turing machines – Practice Questions
Ten original OxfordAQA 9645 questions on sub-topic 3.13.3 Turing machines: transition functions, diagram arcs, hand-tracing, the UTM and their importance.
Computer Science · OxfordAQA · A Level
Try questions -
Revision notes
OxfordAQA A-Level Computer Science (9645): Turing machines – Revision Notes
Recall notes for OxfordAQA 9645 sub-topic 3.13.3: Turing machine parts, transition functions and diagrams, hand-tracing, the UTM and a self-test.
Computer Science · OxfordAQA · A Level
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.