How to use regular expressions in substitution rules?
Summary
This article explains how regular expressions (regex) work inside Clonable and how you can safely use them in substitution rules. It explains important limitations, and shows practical examples you can use right away.
You will learn what regex is useful for, how Clonable’s regex engine behaves, and how to avoid common mistakes that cause rules not to work.
FAQ
Do I need regex knowledge to use Clonable?
Yes, basic regex helps when you want flexible substitution rules.
Why does my regex work elsewhere but not in Clonable?
Clonable uses a non-backtracking regex engine that supports only part of PCRE.
Can regex break my site?
No, but badly written regex can match too much and cause unexpected replacements.
⏱️ Reading time: 7–9 minutes
Regular expressions in Clonable
Regular expressions (often called regex) are available as an option in Substitution rules.
If you already use regex in other tools, it’s important to know that Clonable behaves differently.
Because of this:
- Some complex regex patterns may not work
- Certain patterns may behave differently than expected
- Only a subset of PCRE is supported
If you run into limitations, contact support and include your regex example.
What is a regex used for?
Regex is useful when you want to match many similar pieces of text with one rule.
Typical examples:
- Numbers with different values
- Dates in multiple formats
- Sentences that vary slightly
- Repeating word patterns
Without regex, you would need dozens of separate substitution rules or translations replacements.
Character groups
Character groups define which characters are allowed at a specific position.
They are written between square brackets [].
Examples:
[0-9]matches any digit[A-Z]matches uppercase letters[A-Za-z]matches all letters
Examples in practice:
[Hh]allo
Matches both “Hallo” and “hallo”.
[1-4][0-9][0-9]
Matches any number from 100 to 499.
Quantifiers
Quantifiers define how often a character or group may appear.
They are written using braces {}.
Examples:
{1,3}means between 1 and 3 times{4}means exactly 4 times
Special quantifiers:
?→ 0 or 1+→ 1 or more*→ 0 or more
Examples:
ho{1,2}i
Matches “hoi” and “hooi”.
1[0-9]*
Matches any number starting with 1.
[A-Za-z]{6}
Matches any word with exactly 6 letters.
Using + and *
Using + or * can easily match too much.
To reduce risk, use the lazy versions +? or *? when possible.
Example:
<img src=".*"
This can match far more than intended.
<img src=".*?"
This limits the match to the shortest possible result.
Match groups
Match groups let you combine characters into logical blocks.
They are written between parentheses ().
Examples:
(nom){1,4}
Matches “nom”, “nomnom”, “nomnomnom”, and “nomnomnomnom”.
[A-Za-z]*(ou)[A-Za-z]*
Matches any word containing “ou”.
Using match groups in replacements
Match groups can be reused in the replacement using $1, $2, etc.
Example: move the euro sign from before to after the number.
Original:
€([0-9,]+)
Replacement:
$1€Required options:
- Case insensitive
- Regular expression
- Single word
$1 refers to the first match group in the regex.Using reserved characters
Some characters have special meaning in regex, such as ., ?, and (.
To match them literally, escape them with a backslash ``.
Examples:
Hello\.
Matches only “Hello.”.
\(in\)ternational
Matches “(in)ternational”.
Helpful tips
Keep these rules in mind:
.matches any character.*matches everything[\d]is the same as[0-9][A-z]includes punctuation, not just letters
Practice resources
Want to practice or test your regex?
Useful tools:
These tools help you experiment before adding regex to Clonable.
Tags
pattern matching, text rules, substitution logic, string processing, search replace, expression syntax
Updated on: 06/02/2026
Thank you!
