If you've ever encountered a data set with a field that has been formatted in a bunch of different ways, RegEx can help.
RegEx is essentially a decoder for text. It's a sequence of characters that specifies a search pattern, allowing you to find, extract or replace specific chunks of text accurately. While it looks like a string of gibberish at first glance, understanding what each individual element means will make you an Alteryx wizard.
Where Does RegEx Live in Alteryx?
One of the reasons Alteryx is great is because it integrates RegEx directly into its User Interface, making it accessible even if you aren't a traditional programmer. You will primarily use RegEx in two places:
- The RegEx Tool
This is where most people go to use RegEx in Alteryx. This dedicated tool offers four output methods:
- Parse: Extracts specific parts of a string into new columns and relies heavily on capture groups.
- Match: Returns a simple True/False (or -1/0 in Alteryx terms) if the string matches your pattern, making it great for data validation.
- Replace: Swaps the text that matches your pattern with something else so it's perfect for cleaning up unwanted characters.
- Tokenize: Splits a string into multiple rows or columns based on your pattern.
- The Formula Tool
If you just need a quick function while doing other calculations, Alteryx offers several RegEx formulas:
- REGEX_Match([Field], "pattern") - returns True if the field matches the pattern.
- You can also use REGEX_Match directly inside a Filter Tool to instantly route data based on complex text patterns.
- REGEX_Replace([Field], "pattern", "replacement") - replaces matched text.
- REGEX_CountMatches([Field], "pattern") - counts how many times the pattern appears in the string.
The Qualifiers and Quantifiers Cheat Sheet
To build a RegEx pattern, you combine qualifiers (what kind of character you are looking for) and quantifiers (how many of those characters you want to find). A quantifier only acts on the qualifier directly preceding it.
Qualifiers:
|
REGEX |
Description |
|
. |
Wildcard, any single
character |
|
\l |
Lower case
letter |
|
\u |
Upper case letter |
|
[a-z] |
Letter from a
to z |
|
[A-Z] |
Letter from A to Z |
|
[[:alpha:]] |
Any letter |
|
\w |
Alphanumeric & _
(Word character a-za-Z_0-9) |
|
\W |
NOT
alphanumeric & _ (Word character a-za-Z_0-9) |
|
\< |
Start of word |
|
\> |
End of word |
|
\<\w+\> |
Entire word |
|
\d |
Digits |
|
\D |
NOT digits |
|
[0-9] |
Number from 0
to 9 |
|
` |
` |
|
\ |
Escape special
character E.g. \. Will be an actual "." not a wildcard |
|
\s |
Space |
|
\S |
NOT space |
|
\n |
Newline |
|
^ |
Start anchor
/ beginning of line |
|
$ |
End anchor / end of
line |
|
\t |
Tab |
|
() |
Capture group |
|
(?:) |
Non capture
group |
Quantifiers:
|
REGEX |
Description |
|
* |
Zero or more. (Greedy
– match as much as possible) |
|
+ |
One or more
(Greedy – match as much as possible) |
|
qual? |
Zero or one E.g. Cars?
Will catch car or cars (Lazy / Non-greedy – match as few as possible) |
|
+? *? |
(Modifiers
for Lazy / Non-greedy matching) |
|
quant? |
As few as possible
(Lazy / Non-greedy – match as few as possible) |
|
{x} |
Match exactly
x E.g. \w{3} 3 letter chunks |
|
{x,y} |
Between x and y |
|
{x,} |
Minimum x |
|
[] |
Any one character in
the set E.g. [abc] a or b or c (anything from the set) |
|
[^] |
Any one
character NOT in the set E.g. [^abc] |
Practical Alteryx Examples
Here is how these expressions apply to common data preparation tasks in Alteryx.
1. Standardising Phone Numbers (Replace)
When a phone number field contains inconsistent formatting - such as (123) 456-7890, 123.456.7890, and 123 456 7890 - you can strip it down to raw digits using a Formula Tool:
REGEX_Replace([Phone], "\D", "")
Because \D matches any character that is not a digit, this expression removes all spaces, parentheses, hyphens, and periods, returning 1234567890.
2. Extracting a First Name (Parse)
Suppose a field contains values formatted as Name: Smith, John - Active and you need to isolate the first name. Configure a RegEx Tool with the Output Method set to Parse and enter the following pattern:
,\s(\w+)
This pattern locates the literal comma followed by a single space (\s). Wrapping \w+ in parentheses creates a capture group for one or more word characters immediately after that space, instructing Alteryx to output only John into a new column.
3. Validating UK Postcodes (Match)
To separate valid UK postcodes (such as SW1A 1AA, M1 1AE, or B33 8TH) from malformed entries, use a Filter Tool with the following expression:
REGEX_Match([Postcode], "^[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}$")
Breaking this down using the cheat sheet:
- ^ and $ anchor the pattern to the start and end of the string so partial matches are excluded.
- [A-Z]{1,2}\d[A-Z\d]? validates the outward code (one or two letters, a digit, and an optional second digit or letter).
- \s? allows for an optional space between the two halves.
- \d[A-Z]{2} validates the inward code (one digit followed by exactly two letters).
Any record that fails to meet this structure will route to the False anchor for review.
Overall...
The most effective way to build confidence with RegEx is to start with straightforward clean-up tasks - such as removing punctuation or standardising whitespace - before moving on to multi-group parsing. Keeping a reference table nearby while building workflows makes it much easier to combine qualifiers and quantifiers accurately.
