Skip to content
All apps

RegEx trainer

About this app

Regular expressions with instant feedback: type a pattern and watch live what re.finditer grabs in the text — matches glow in alternating colours, the match list shows positions and groups. Five tasks (numbers, emails, dates, backreferences …) with target checking, hints and an insertable solution, plus flags (re.I/M/S) and a cheat sheet.

What regular expressions are

A regular expression is a search pattern for text. Character classes such as \d or [A-Z] stand for a set of characters, quantifiers such as +, * or {4} say how often something may occur, parentheses form groups, and a backreference such as \1 requires the same text to appear again. Quantifiers are greedy by default and take as much as possible; a trailing ? makes them lazy. In Python, re.finditer returns all non-overlapping matches in order, and flags such as re.I ignore case.

What the app shows

A pattern field in Python notation and below it a practice text in which every match lights up instantly in alternating colours. A status line shows the number of matches or the error message, and a list shows each match with its position and groups. The flags re.I, re.M and re.S can be switched on as chips. A cheat sheet sums up the most important building blocks.

Try it yourself

Besides free mode there are five tasks: integers, capitalised words, email addresses, dates in DD.MM.YYYY format and directly repeated words via a backreference. A target check counts how many of the wanted spans your pattern hits; a hint and an insertable solution help you along. The practice text can be edited freely.

Frequently asked questions

What is the difference between greedy and lazy in regex?
A greedy quantifier such as .* takes as many characters as possible and only gives some back if the rest of the pattern would otherwise fail. A lazy quantifier such as .*? takes as few as possible. On <b>x</b>, <.*> matches the whole text, <.*?> only <b>.
What is a backreference in a regular expression?
A backreference such as \1 stands for exactly the text the first capturing group matched. The pattern \b(\w+) \1\b therefore finds directly repeated words such as “the the”.
What does re.finditer do in Python?
re.finditer(pattern, text) returns all non-overlapping matches in order as match objects. Each one knows its start and end position (start(), end()) and the contents of its groups (group(1) and so on).
Which tasks does the regex trainer offer?
Five tasks: integers, capitalised words, email addresses, DD.MM.YYYY dates and repeated words with a backreference. Each has a target check, a hint and a solution to insert; there is also a free mode with your own text.

Subject: Computer science

More from Computer science

A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps