Regular Expression Tester
Write formal regular expressions and test them against input strings. Uses a proper NFA-based engine (not JavaScript regex) so the behaviour matches AQA exam notation. Spec reference: §4.4.2.
📖 Learn Step-by-Step✓ Valid regex
Formal regex syntax:
Test Strings
Regular Expression Practice Questions
The regular expression (a|b)*a matches all strings over {a,b} that end with 'a'. How many of these 8 strings does it match: a, b, aa, ab, ba, bb, aba, bba?
How many distinct strings of length exactly 2 are in the language described by (0|1)(0|1)?
The regex a*b matches strings of zero or more 'a's followed by exactly one 'b'. What is the length of the shortest string this regex matches?
Given the regex (ab|cd)*, how many strings of length 4 belong to the language?
A regular expression over {0,1} matches all binary strings containing '11' as a substring. It can be written as (0|1)*11(0|1)*. How many strings of length 3 does it match?
Quick reference — Regular Expressions
What is a regular expression?
A regular expression (regex) is a pattern that describes a set of strings — a regular language. In formal CS (as opposed to programming regex), the operations are concatenation, alternation (|), and Kleene star (*).
Formal operators
| ab | Concatenation — 'a' followed by 'b' |
| a|b | Alternation — 'a' or 'b' |
| a* | Kleene star — zero or more 'a's |
| a+ | One or more 'a's (shorthand for aa*) |
| a? | Optional — zero or one 'a' |
| ε | The empty string |
Equivalence with FSMs
Every regular expression can be converted to an equivalent FSM (DFA or NFA), and vice versa. This tool uses Thompson's construction to build an NFA from the regex, then simulates it.
AQA exam tips
- Operator precedence: * binds tightest, then concatenation, then |
- Use brackets to clarify grouping
- Remember: a* includes the empty string ε
- You may be asked to write a regex, draw an equivalent FSM, or analyse which strings match