Regular Expressions
Aligned to the AQA 7517 specification
- Level
- Advanced
- Reading time
- 8 min
- Published
- 6 June 2026
- Updated
- 1 July 2026
On this page
Key takeaways
- A regular expression is a compact notation describing a set of strings (a language); every string that matches the pattern is a member of that set.
- The five metacharacters assessed by AQA are `*`, `+`, `?`, `|` and `( )`; any character that is not a metacharacter is a literal that matches itself.
- `a*` includes the empty string (zero or more repetitions), whereas `a+` requires at least one repetition and excludes the empty string.
- A language is regular if and only if it can be represented by a regular expression, which is equivalent to being accepted by a finite state machine.
- Regular expressions can only describe regular languages, so patterns needing counting like {0ⁿ1ⁿ | n ≥ 1} cannot be expressed and require formalisms such as BNF.
Want more lessons like this one?
Generate lessons on anything you study. Free account, no card needed.
Key terms
- Regular expression
- A compact notation that describes a set of strings (a language) by defining a pattern that member strings match.
- Metacharacter
- One of the special characters `*`, `+`, `?`, `|`, `( )` that AQA assesses, used to build patterns rather than match itself.
- Literal
- Any character that is not a metacharacter, which matches itself exactly.
- Star (Kleene star) `*`
- Matches zero or more repetitions of the preceding element, including the empty string.
- Plus `+`
- Matches one or more repetitions of the preceding element, excluding the empty string.
- Question mark `?`
- Makes the preceding element optional by matching zero or one repetition.
- Pipe (alternation) `|`
- Matches either the left or the right alternative, acting as a logical OR.
- Parentheses `( )`
- Group a sub-expression so an operator applies to the whole group rather than a single element.
- Empty string (ε)
- The string with zero symbols, matched by `*` but not by `+`.
- Language
- Any set of strings over a given alphabet.
- Regular language
- A language that can be described by a regular expression, equivalently one for which a finite state machine accepting exactly its strings can be built.
- Finite state machine (FSM)
- A machine equivalent to a regular expression that accepts exactly the strings of a regular language.
Frequently asked questions
`*` means zero or more repetitions of the preceding element, so it includes the empty string. `+` means one or more repetitions, so it requires at least one occurrence and does not match the empty string. If the question says 'one or more', use `+`.
It matches one literal 'a' followed by zero or more repetitions of either 'a' or 'b', so it generates the set {a, aa, ab, aaa, aab, aba, …}: any string that starts with 'a' followed by any sequence of a's and b's. It does not match b, ba or the empty string.
No. Regular expressions can only describe regular languages. Patterns with balanced brackets, matching open/close tags, or equal numbers of two symbols such as {0ⁿ1ⁿ | n ≥ 1} cannot be expressed with the five metacharacters and require more powerful formalisms such as context-free grammars (BNF).
Generate revision on any topic you study
Type any topic you're studying and Aicademy generates a complete lesson, quiz, and flashcard set, personalised to your level.
Lessons on anything
Structured, level-matched lessons on any topic you study
Practice quizzes
Find out what you actually know before the exam does
Flashcard sets
Lock in key concepts with instant revision cards
Ask Aica
Stuck on something? Get a clear explanation, any time
Sets and Formal Languages
BNF and Syntax Diagrams
Related lessons
9 min
5 min
6 min