Step 1 of 12
Regex practice exercises: what you'll practise
In this lesson you practise regular expressions with exercises and answers, in a live tester that marks every match as you type the pattern. You work on log lines, support ticket IDs, order numbers, dates in reports and emails in a CSV export, and learn one new token a step.
A regular expression (regex) is a pattern that describes text: "TCK-, then digits" instead of every ticket number one by one. Search boxes in editors, spreadsheets, log tools, grep and every programming language understand them.
Press Play and watch a pattern grow one token at a time. Under the pattern, each token is explained in words; in the text, every match is marked.
In this lesson you'll:
- match exact text, any character, and one character from a set
- say how many times something repeats (
+,*,?,{4}) - pin a match to the start or end of a line, or to a whole word
- capture parts of a match, such as the month of a date or the domain of an email
- check what comes before or after a match without including it
It takes about 70 minutes. Each step has a tester with two to four tasks; a task ticks itself when your pattern finds exactly the text it wants, and the text it wants is underlined with a dashed green line. Stuck? Hint, then Show answer.
The tester runs JavaScript's regex engine, the one in every browser. Most of what you learn works the same in Python, Java, C#, VS Code and grep -E; where they differ, the step says so.
Takeaway: a regex is a pattern; the engine finds every place in the text that fits it.