Picture of Regex Text Manipulations | IV_016

Regex Text Manipulations | IV_016

In this tutorial, we learn how to utilise Regex (Regular Expression) Text Manipulation to format text strings. These can be set up on a text variable within Infigo Invent, in order to ensure consistency of data formats on your products. Regex (regular expressions) is a powerful tool for text manipulation that allows you to search, match, and manipulate patterns within strings of text. It is not specific to Infigo, so there are loads of internet resources available to assist with the creation of Regex expressions.

Tutorial Video Transcript

00:00:11:21 - 00:00:15:03
RegEx
or regular expressions is a powerful tool

00:00:15:03 - 00:00:17:16
for text manipulation
that allows you to search,

00:00:17:16 - 00:00:20:24
match and manipulate patterns
within strings of text.

00:00:21:10 - 00:00:24:26
So a brief summary of Regex
text manipulation,

00:00:24:26 - 00:00:28:05
which will go on to in a minute
and how you can use it within Infigo.

00:00:28:24 - 00:00:31:24
So there's a few things
that you can do with it.

00:00:31:24 - 00:00:36:03
So pattern matching being one
regex enables you to search for specific

00:00:36:03 - 00:00:39:16
patterns or sequences of characters
within a text string

00:00:40:14 - 00:00:45:09
by defining a pattern
using special syntax and meta characters,

00:00:45:09 - 00:00:47:22
you can find matches
within the target text.

00:00:49:15 - 00:00:53:15
You can also do string searching,
so Regexs allows you to perform advanced

00:00:53:15 - 00:00:57:09
search operations, which is finding
all occurrences of a specific word

00:00:57:20 - 00:01:00:08
or identifying patterns
that follow certain rules.

00:01:00:27 - 00:01:03:18
It provides
more flexibility than simple string

00:01:03:18 - 00:01:07:25
searches, validation

00:01:07:25 - 00:01:12:28
and extraction, so regex can be used to
validate and extract specific information

00:01:12:28 - 00:01:17:20
from text for example,
you can validate email addresses, URLs

00:01:17:27 - 00:01:21:02
or phone numbers
by defining regex patterns

00:01:21:10 - 00:01:24:10
match the expected format.

00:01:25:13 - 00:01:25:28
We've also got

00:01:25:28 - 00:01:29:05
text manipulation,
so with regex you can manipulate text

00:01:29:05 - 00:01:32:22
by replacing or modifying
specific patterns within a string.

00:01:33:05 - 00:01:38:07
This includes tasks like find and replace
operations, formatting

00:01:38:07 - 00:01:44:07
and reformatting text and transforming
data into the desired format.

00:01:44:18 - 00:01:48:11
You've got text parsing,
so Regexs is often used for passing

00:01:48:11 - 00:01:51:02
structured data from unstructured text

00:01:51:16 - 00:01:54:26
by refining regex patterns
to match specific

00:01:54:26 - 00:01:58:25
data patterns, you can extract meaningful
information from text such

00:01:58:25 - 00:02:03:29
as extracting dates, addresses
or other structured data.

00:02:03:29 - 00:02:06:07
And you've also got data
cleaning operations.

00:02:06:07 - 00:02:10:09
So regex is useful for data
cleaning tasks, such as removing

00:02:10:09 - 00:02:14:28
unnecessary characters, normalizing
data formats, removing duplicates

00:02:15:05 - 00:02:18:13
or correcting inconsistencies
in textual data.

00:02:19:26 - 00:02:22:27
So regex provides
a versatile and flexible way

00:02:22:27 - 00:02:26:26
to perform complex, complex
text manipulation tasks.

00:02:27:13 - 00:02:30:24
By mastering regex or learning
how to utilize regex,

00:02:30:24 - 00:02:35:04
You can efficiently search, validate and
manipulate text based on specific patents,

00:02:35:05 - 00:02:40:08
making it a valuable tool for various
programing and text processing operations.

00:02:41:04 - 00:02:45:02
Now, regex is not something that specific
to Infigo so there are loads of internet

00:02:45:02 - 00:02:49:04
resources available to assist you
with the creation of expression.

00:02:51:04 - 00:02:53:27
What I'm going to talk about here
is how we've incorporated

00:02:53:27 - 00:02:58:19
this regex functionality
into in Infigo Invent.

00:02:58:19 - 00:03:03:04
So the example I'm

00:03:03:04 - 00:03:06:21
going to utilize
here is the formatting of a phone number.

00:03:07:02 - 00:03:10:24
So in my example,
I have a basic business card,

00:03:10:24 - 00:03:13:17
but on the back of that business card
we have a telephone number.

00:03:14:06 - 00:03:17:13
And what we might want to make sure
is that all every telephone number

00:03:17:13 - 00:03:21:12
that's input
is put into a consistent format.

00:03:21:12 - 00:03:25:01
And this is just one of the many
potential applications for regex.

00:03:26:02 - 00:03:28:20
How we would actually set that up
within Invent itself

00:03:29:07 - 00:03:31:28
is within a variable itself.

00:03:33:05 - 00:03:35:07
So if I create a new variable

00:03:35:07 - 00:03:40:11
within Invent, I could say add variable

00:03:41:15 - 00:03:43:17
and then choose a text variable.

00:03:45:06 - 00:03:48:03
In my example, I'm just going to edit
my existing variable

00:03:48:03 - 00:03:53:15
that I've created again
into the text variable type.

00:03:53:15 - 00:03:57:15
And then what you'll find on the bottom
left of this screen that pops up

00:03:57:24 - 00:04:00:02
is Regexs text manipulation.

00:04:00:16 - 00:04:04:21
And this gives you the ability to so it's
between a few predefined expressions

00:04:05:01 - 00:04:07:19
or you can generate your own expression

00:04:08:06 - 00:04:11:22
if you've got the ability to do so.

00:04:11:22 - 00:04:15:08
So we've got regex text manipulation,
which is showing you the applied rules

00:04:16:11 - 00:04:19:21
and we've got a series of predefined
default manipulations.

00:04:20:09 - 00:04:24:12
All of this stage is picked
the length of the phone number

00:04:24:12 - 00:04:29:05
I'm expecting click add
and then I will add it to the existing

00:04:29:05 - 00:04:36:07
regex text manipulations
that will be applied to that variable.

00:04:36:07 - 00:04:38:17
Now you don't have to stick
with the default formats.

00:04:38:17 - 00:04:41:07
If you want to tweak it slightly,
you can just click on edit

00:04:41:18 - 00:04:44:12
and that will take you
to this additional screen where you can

00:04:44:12 - 00:04:50:25
modify and tweak those expressions
slightly.

00:04:50:25 - 00:04:54:27
In addition, if you want to add your own
regex text manipulation expression,

00:04:55:06 - 00:04:58:14
you can click on Add
a regex text manipulation at the bottom

00:04:58:26 - 00:05:07:18
where you can define
your own string for use.

00:05:07:18 - 00:05:10:03
So what I've selected
here is the ten digit phone number,

00:05:10:12 - 00:05:14:11
and then just as my default value,
just as a point of reference, I've put in

00:05:14:22 - 00:05:18:15
ten digits, which will in this case
represent our telephone number.

00:05:19:17 - 00:05:19:27
And then I'm

00:05:19:27 - 00:05:22:23
going to click on Save from the Bottom
right to save the variable

00:05:23:19 - 00:05:26:28
and then just make sure that you've linked
that variable to the relevant

00:05:27:20 - 00:05:36:23
frame on your artwork itself.

00:05:36:23 - 00:05:39:23
Now, all I've done at this stage and I'm
going to set these steps as covered

00:05:39:23 - 00:05:42:25
in different
tutorials, is export that template

00:05:43:02 - 00:05:46:03
and then import it back into MegaEdit
and launch

00:05:46:04 - 00:05:47:07
the MegaEdit editor.

00:05:48:15 - 00:05:51:16
And then what we'll see in here
once we launch this is over on the right

00:05:51:16 - 00:05:52:01
hand side.

00:05:52:01 - 00:05:55:29
I have my text inputs
with my telephone number,

00:05:56:27 - 00:05:59:25
but then if I look at it
on the actual artwork itself,

00:05:59:25 - 00:06:03:21
we can see that those regex text
manipulation

00:06:03:21 - 00:06:06:19
expressions have been applied to that
telephone number.

00:06:07:04 - 00:06:09:24
So it's reformatted
completely from what I've entered here

00:06:10:01 - 00:06:15:05
into our desired format.

00:06:15:05 - 00:06:17:07
You can see
if I had more than ten characters,

00:06:17:07 - 00:06:21:07
it reverts because it's only
about the ten character limit.

00:06:21:07 - 00:06:30:10
Or if I change some of the characters,
it will format it in the same way.

00:06:31:05 - 00:06:35:16
So that's a very basic example
of how we could utilize regex expressions.

00:06:35:25 - 00:06:39:04
As I mentioned, the possibilities
are much, much greater with this,

00:06:39:21 - 00:06:43:20
and there's plenty of Internet
resources to assist you in that task.

 

Incomplete
Understanding the Regex Input Fields in Invent

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.


Typical use cases

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:

  1. check whether the value is in a state where it should be reformatted, and

  2. if so, slice it into pieces and rebuild it in a new layout.


The Regex fields in an Invent text variable

When you edit a text variable and add a Regex Text Manipulation, you’ll see these fields:

1. Condition Regular Expression

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)

 
^\s*(?:[0-9]\s*){10}$

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.


2. Replacement Regular Expression

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)

 
^(\d{3})(\d{1,3})(\d{1,4})?(\d{1,4})?

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:

  • $1123

  • $2456

  • $37890

  • $4(empty)


3. Replacement String

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)

 
($1) $2-$3 $4

Using the same example groups as above:

  • ($1)(123)

  • space →

  • $2456

  • --

  • $37890

  • space + $4 → (blank if group 4 didn’t match)

Final result:

 
(123) 456-7890

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.


Complete worked example: reformatting a 10-digit telephone number

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

     
    ^\s*(?:[0-9]\s*){10}$

    Only run the manipulation when the field contains exactly 10 digits (ignoring spaces).

  • Replacement Regular Expression

     
    ^(\d{3})(\d{1,3})(\d{1,4})?(\d{1,4})?

    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

     
    ($1) $2-$3 $4

    Rebuild the value as (area code) first-part–second-part [optional extra part].

User experience

  1. The user starts typing digits: 0, 01, 0123, etc.

    • Condition regex does not match yet → value is left unchanged.

  2. 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.

Alternate Search Terms

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