Invent text variables support Regex Text Manipulation.
This allows you to automatically reformat what a user has typed, based on patterns you define.
A common example is phone numbers: a user types 0123456789 and Invent reformats it to something more readable like (012) 345-6789 as soon as enough digits are present.
This article explains the three Regex fields you see in an Invent text variable:
Condition Regular Expression
Replacement Regular Expression
Replacement String
…and walks through a complete example using a 10-digit telephone number.
Some common scenarios where Regex text manipulation is useful:
Reformatting phone numbers
Convert raw digits into a consistent pattern: (012) 345-6789.
Normalising spaces or punctuation
For example, forcing postcodes or IDs into a standard format.
Splitting a single input into logical parts
Such as country code, area code, and subscriber number.
In all cases, the idea is the same:
check whether the value is in a state where it should be reformatted, and
if so, slice it into pieces and rebuild it in a new layout.
When you edit a text variable and add a Regex Text Manipulation, you’ll see these fields:
What it does
The Condition Regular Expression decides whether the manipulation should run at all.
If the current field value matches this pattern, Invent continues and applies the replacement.
If it does not match, Invent leaves the value exactly as it is.
Think of it as the “gatekeeper” or pre-condition.
Example (phone number)
Plain-language meaning:
^ and $ – anchor the pattern to the start and end of the value.
\s* – allow optional spaces.
(?:[0-9]\s*){10} – “ten digits, each optionally followed by spaces”.
In other words:
The value must contain exactly 10 digits (ignoring spaces) and nothing else.
Until the user has supplied 10 digits, the condition will not match and no reformatting happens.
What it does
Once the condition has passed, the Replacement Regular Expression defines how to slice the value into parts. These parts are called capture groups.
Each pair of parentheses (...) creates a group, which you can then refer to later in the replacement string using $1, $2, and so on.
Example (phone number)
Breaking it down:
^ – start of the value.
(\d{3}) – Group 1: the first 3 digits (e.g. area code).
(\d{1,3}) – Group 2: the next 1–3 digits.
(\d{1,4})? – Group 3 (optional): the next 1–4 digits.
(\d{1,4})? – Group 4 (optional): the next 1–4 digits.
Groups 1 and 2 are required; groups 3 and 4 are optional because of the ? at the end of each group. If those groups don’t match anything, $3 or $4 will simply be empty in the replacement.
So for the value 1234567890, you might end up with:
$1 → 123
$2 → 456
$3 → 7890
$4 → (empty)
What it does
The Replacement String describes how to rebuild the text, using the capture groups from the Replacement Regular Expression.
You can mix literal characters (spaces, brackets, dashes, etc.) with group references like $1, $2, $3.
Example (phone number)
Using the same example groups as above:
($1) → (123)
space →
$2 → 456
- → -
$3 → 7890
space + $4 → (blank if group 4 didn’t match)
Final result:
If group 4 is not present, you just get an extra trailing space, which can be removed by tightening the pattern or tweaking the replacement string.
Imagine we have an Invent text variable called Telephone.
We want users to be able to type 0123456789, and once they’ve entered 10 digits, automatically reformat it to (012) 345-6789.
Configuration
Condition Regular Expression
Only run the manipulation when the field contains exactly 10 digits (ignoring spaces).
Replacement Regular Expression
Split the digits into up to four groups:
Group 1: first 3 digits
Group 2: next 1–3 digits
Group 3: next 1–4 digits (optional)
Group 4: next 1–4 digits (optional)
Replacement String
Rebuild the value as
(area code) first-part–second-part [optional extra part].
User experience
The user starts typing digits: 0, 01, 0123, etc.
Condition regex does not match yet → value is left unchanged.
Once the user has entered 10 digits: 0123456789
Condition regex matches → Invent applies the replacement.
Replacement regex creates capture groups from the digits.
Replacement string outputs (012) 345-6789.
The user ends up with a nicely formatted phone number, without needing to worry about where to put spaces and brackets.
By combining these three fields—Condition, Replacement Regex, and Replacement String—you can build powerful, reusable text transformations in your Invent variables, while keeping the user experience simple and consistent.
auto format phone number in Invent text field, set up regular expression text manipulation in Infigo, input mask for telephone field in MegaEdit, use regex to reformat user input on products, normalise spaces and punctuation in text variables, split phone number into area code and subscriber number, condition and replacement regex examples for Invent, validate and reformat 10 digit telephone numbers, automatically tidy customer data using regex, regex rules for consistent data formatting in Invent