A regular expression (regex) is a text pattern. In Auto Filing variables you use one to test whether an email contains something, such as a matter number in the subject, and to pull that value out for a folder path, a file name or a dataset lookup. This page explains how mxHERO evaluates patterns, how to reuse the parts you capture, and gives a short syntax reference with tested-style examples.
Before you begin
- Know how to create a variable. See Custom Variables.
- Have a sample email (
.emlor.msg, up to 25 MB) or sample text to test with.
How mxHERO evaluates patterns
mxHERO uses a Java-style regex engine (jregex). Three rules matter most:
| Rule | What it means for you |
|---|---|
| Always case-insensitive |
invoice matches Invoice, INVOICE and invoice. You don't need (?i). Don't rely on letter case to tell values apart. |
| Always multiline |
^ and $ match at the start and end of each line, not only of the whole text. This matters for the email body and attachment text, which have many lines. |
| A match anywhere counts | The pattern doesn't have to cover the whole value. \d{6} matches a subject that contains six digits. Use ^ and $ to require a full-line match. |
Other behavior:
- Multi-value sources are tested value by value. Sources such as All Recipients or attachment names can hold several values. The pattern is tested against each one, and each match produces its own result. Duplicate results are removed (ignoring case).
-
Date sources can also be matched with a regex. The pattern is applied to the date as text in the variable's format, for example
20261019for ayyyyMMdddate. - An invalid pattern is rejected when you save or test the variable, with an error that the regex format is wrong.
Where you use regular expressions
- Variable conditions. In Auto Filling › Variables, choose the matches regex condition for a source (subject, body, sender, attachment name, and so on).
- Dataset lookups. With matches regex, you can choose to look up the captured value in a dataset (exact key or "key contains the value"). See Look up a captured value in a dataset.
- Everything built on variables. Storage file paths, file names, and Copy, Filter, Security and Template policies use the variables you build with regex.
Capture groups and the values you can reuse
Parentheses ( ) create a capture group. Groups are numbered from left to right by their opening parenthesis. Group 0 is always the whole match.
Example: pattern INV-(\d{4})-(\d{3}) on the subject Re: INV-2026-042 overdue:
| Group | Value |
|---|---|
| 0 | INV-2026-042 |
| 1 | 2026 |
| 2 | 042 |
To use a group in the variable's convert value:
- In the convert value field, type
{. - Pick the regex group from the list. The dashboard inserts a placeholder for that group of that condition.
In mxHERO's placeholder syntax, a regex group is written {GROUP-n}, where n is the group number ({GROUP-0} is the whole match). When a variable has several conditions, the picker inserts the group together with the condition it belongs to.
Important: The
${1}syntax shown in older mxHERO articles and in many regex tutorials does not work in mxHERO convert values. Use the placeholder picker.
You can combine groups with fixed text and other variables, for example Invoices/{GROUP-1}/{GROUP-2} to file into Invoices/2026/042.
Look up a captured value in a dataset
- In the variable condition, choose matches regex and enter the pattern.
- As the Action, choose and map with and select the dataset under Datasets.
- Choose how the key is matched:
-
when the key is equal to: the dataset key must equal the captured value (default lookup key: the whole match,
{GROUP-0}). - when the key contains: the dataset key must contain the captured value.
-
when the key is equal to: the dataset key must equal the captured value (default lookup key: the whole match,
- In the convert value, insert the dataset value placeholder to use the row's value.
Dataset keys are compared case-insensitively, and spaces at either end are ignored. See Datasets.
Test a pattern
- Open the variable in Auto Filling › Variables.
- Click Test variable.
- Click Upload an email to upload a sample
.emlor.msgfile, or enter text in the Fields, then click Test. - To try the pattern on its own, click Test inside the Value field to open the regex tester, enter the pattern and sample text, and check the match and groups. Use the tester's option to copy the pattern back into the condition.
Test with real-looking samples, including ones that should not match.
Syntax reference
Characters and positions
| Pattern | Matches |
|---|---|
. |
Any single character (except a line break) |
^ / $
|
Start / end of a line |
[abc] |
One of a, b or c |
[^abc] |
Any character except a, b or c |
[a-d1-7] |
A letter from a to d, or a digit from 1 to 7 |
X|Y |
X or Y |
\. \( \[
|
A literal ., ( or [ (escape special characters with \) |
Character classes
| Pattern | Matches | Opposite |
|---|---|---|
\d |
A digit [0-9]
|
\D |
\s |
Whitespace (space, tab, line break) | \S |
\w |
A word character [a-zA-Z_0-9]
|
\W |
\b |
A word boundary (position, not a character) | \B |
Quantifiers
| Pattern | Meaning |
|---|---|
* |
0 or more |
+ |
1 or more |
? |
0 or 1 (optional) |
{3} |
Exactly 3 |
{1,4} |
1 to 4 |
*? +?
|
As few as possible ("lazy") |
Groups and look-ahead
| Pattern | Meaning |
|---|---|
( ) |
Capture group |
(?: ) |
Group without capturing (doesn't get a number) |
(?!abc) |
Not followed by abc
|
(?=abc) |
Followed by abc
|
Examples
| Goal | Source | Pattern | Use |
|---|---|---|---|
Matter number such as M-12345
|
Subject | \bM-(\d{5})\b |
{GROUP-1} → 12345
|
Invoice year and number INV-2026-042
|
Subject or attachment name | INV-(\d{4})-(\d+) |
{GROUP-1}/{GROUP-2} |
| Policy number after a label in the body | Body text | Policy\s*(?:No\.?|Number)\s*:?\s*([A-Z0-9-]+) |
{GROUP-1} |
| US Social Security number | Body text or attachment text | \b\d{3}-\d{2}-\d{4}\b |
Condition only (apply a Security Definition) |
| Sender domain without the TLD | Sender address | @([^.]+)\. |
{GROUP-1} → example
|
| PDF attachments | Attachment name | \.pdf$ |
Condition only |
| Subject that starts with a tag | Subject | ^\[Project ([^\]]+)\] |
{GROUP-1} |
Note: Subject sources may already have reply and forward prefixes (
Re:,Fwd:and similar) removed. Pick the subject source that fits your pattern. See Variables Reference.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Error when saving or testing the variable | Invalid pattern, for example an unclosed ( or [
|
Check brackets; escape ., (, [, +, ? when you mean the literal character. |
Folder name shows ${1} or a placeholder as text |
Old ${n} syntax or a typed placeholder |
Insert the group with the { picker. |
| Pattern matches too much | Greedy quantifiers such as .*
|
Use a narrower class ([^\s]+, \d+) or a lazy quantifier (.*?). Add \b, ^ or $. |
| Pattern never matches body text | Expecting ^/$ to mean the whole text, or . to cross lines |
Remember ^/$ work per line; use [\s\S]*? to span lines. |
| Case-sensitive match needed | Matching is always case-insensitive | Match on another property of the value (position, format, surrounding text). |
Comments
0 comments
Please sign in to leave a comment.