Regular expressions (RegEx) — made simple
What a regular expression is, where FlowBotCommander offers it (window title, Check text) and the ten characters you really need — with examples from games.
In two places FlowBotCommander offers the match type Regular expression. You do not need it — "contains", "starts with" and "ends with" are almost always enough. But when a text keeps changing (numbers, times, tab counters in the window title) or OCR mixes up letters, a small pattern gets you further. This article explains exactly as much RegEx as you need for that.
What is a regular expression?
A regular expression (RegEx for short) is a pattern that describes what a text may look like — instead of
a fixed word. "Contains Gold" only matches the word Gold. The pattern Gold: \d+ matches "Gold: 5",
"Gold: 120", "Gold: 99999" — any number after "Gold: ".
Normal letters and digits stand for themselves in the pattern. Only a few special characters have a meaning:
| Character | means | Example | matches |
|---|---|---|---|
. |
any one character | L.vel |
Level, Lövel, L3vel |
\d |
one digit 0–9 | Lv \d |
Lv 1, Lv 7 |
+ |
the previous thing one or more times | \d+ |
5, 12, 99999 |
* |
the previous thing zero or more times | Gold *\d+ |
Gold5, Gold 5, Gold 5 |
? |
the previous thing optional (0 or 1 times) | Lv\.? \d+ |
Lv 3, Lv. 3 |
^ |
start of the text | ^Victory |
"Victory!" — not "No victory" |
$ |
end of the text | Editor$ |
"Doc – Editor" |
[abc] |
one of these characters | Lv[. :] |
Lv. / Lv: / Lv␣ |
[0-9] |
one character from the range | [1-3] |
1, 2 or 3 |
a|b |
a or b | Victory|Sieg |
Victory or Sieg |
\. |
a real dot (instead of "any character") | 1\.5 |
1.5 — not 1x5 |
Special characters you mean literally (. + * ? ( ) [ ] | $ ^) get a backslash in front:
\. \+ \(. Upper and lower case do not matter in FlowBotCommander — victory also matches "VICTORY".
Where you find RegEx in FlowBotCommander
1. Window title — match type "Regular expression"
In Start (global match type), Switch image source, Bring window to front, Move/Resize window and the overlay nodes you choose how the window title is compared (see Window and image source). Usually contains is enough. You need RegEx when two windows have similar names:
| Situation | Pattern | Explanation |
|---|---|---|
| Only the browser tab with the game, not the tab with the wiki | ^Clicker Heroes |
title must start with "Clicker Heroes" |
| Title alternates between "Game (1)", "Game (2)" … | ^Game \(\d+\)$ |
brackets literally, a number in between |
| Exactly "Editor" at the end, whatever comes before | Editor$ |
title ends with Editor |
| English or German client | Inventory|Inventar |
one of the two |
2. Check text — mode "Regular expression"
The condition node Check text compares a text (usually from Read text (OCR)) with your pattern and returns true or false at the result output — which you connect to a Branch (see Loops and conditions). Examples:
| You want to know … | Pattern | matches e.g. |
|---|---|---|
| Is there any number in the text? | \d+ |
"Gold 250" |
| Is it a number from 100 (three or more digits)? | \d{3,} |
100, 2500 — not 99 |
| Is the fight over — in any language? | Victory|Sieg|Defeat|Niederlage |
"VICTORY!" |
| Is a countdown running (mm:ss)? | \d\d:\d\d |
"02:59" |
| Is there "Level" plus a number although OCR eats the dot? | L[ev]*\.? *\d+ |
"Lv. 5", "Lvl 5", "Level 5" |
You rarely need RegEx for numbers: for "Gold ≥ 50" rather use Number from text (extracts the first number from the text) and then Compare number — that is readable without a pattern. RegEx pays off for words, formats and "any of these".
Catching OCR errors
Text recognition likes to read "Lv. 1" as "L"; 1" or "0" as "O" (see Read text (OCR)). Instead of moving the region for the tenth time, make the pattern tolerant:
- Confused letters as a set:
[O0]matches O and 0,[Il1]matches I, l and 1. - Make uncertain characters optional:
Lv\.? ?\d+allows dot and space — or not. - Only check the safe part: instead of "Ready for battle!"
Readyis enough.
How to test a pattern
- Create a Check text node, mode Regular expression, enter the pattern.
- Connect a variable with an example text as input (or the OCR node directly).
- Start the bot with F5 and look in the log: the node writes "Text check ⇒ True" or "False".
- Build the pattern step by step: first
Gold, thenGold \d, thenGold \d+— so you see immediately which part does not match.
If it doesn't work: an invalid pattern (e.g. an open bracket () makes the node always evaluate to false
— without an error message. Most common causes: dot without backslash (1.5 also matches "125"), forgotten +
(\d matches only one digit), spaces in the text that are missing in the pattern. When in doubt start with
contains and a short word — RegEx only when that is not enough.