Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 1

Parsing Data with RegEx

Recommended resources

Hello! Welcome to your first lesson in this course designed to help you achieve the Alteryx Advanced Certification.

This first module focuses on Advanced Parsing and Data Integration. Since you already hold the Core Certification, you're familiar with handling well-structured data. Now, we'll dive into the more complex, real-world challenge of wrangling data from less-structured sources like text fields, APIs, and nested data formats.

Today's lesson addresses the first learning outcome: parsing and extracting data from strings using the RegEx tool and regular expression syntax. This is a powerful and essential skill, not just for the exam, but for any serious data work. We'll cover what Regular Expressions (RegEx) are, how to use the Alteryx RegEx tool, and most importantly, how to write expressions to parse out the exact information you need.

1. What are Regular Expressions (RegEx)?

You've likely used Alteryx's standard string functions (like LEFT(), RIGHT(), FINDSTRING()) in your Core certification work. These are great for simple, predictable tasks. But what if you need to extract an email address from a block of text, where its position and length can vary? Or pull all product codes that follow a pattern like "two letters, three numbers, one letter"?

This is where Regular Expressions shine.

A Regular Expression (RegEx) is a special sequence of characters that defines a search pattern. Instead of searching for a fixed string, you search for a pattern, giving you incredible flexibility to find, extract, and manipulate complex text data.

To get a solid introduction, please read the first few sections of the following article from phData.

A Beginner's Guide to Alteryx: How to Use Regular Expressions

This article provides a great starting point for understanding what RegEx is and why it's a 'superpower' for data preparation.

Please read the introduction and the section titled 'What are Regular Expressions?'


2. The RegEx Tool in Alteryx

In Alteryx, your primary tool for this is, unsurprisingly, the RegEx tool, found in the "Parse" tool palette. It allows you to apply a regular expression to a column and perform one of several actions.

This image gives a high-level overview of the different ways the RegEx tool can operate. Today, we'll be focusing on the Parse method.

Alteryx RegEx Tool Output Methods Overview
This image provides a summary of the RegEx tool's output methods: Match, Parse, Replace, and Tokenize. We will focus on the 'Parse' method in this lesson.

To understand the tool's interface, please return to the article you just started.

A Beginner's Guide to Alteryx: How to Use Regular Expressions

This section walks you through the configuration pane of the RegEx tool, explaining each of the main options.

Read the section 'How to Use the RegEx Tool in Alteryx'. Pay close attention to the screenshot of the configuration window and the description of its parts.


3. Parsing Data with Marked Groups

The key to extracting data with the RegEx tool's Parse method lies in defining marked groups (or capture groups). A marked group is any part of your regular expression that you enclose in parentheses ().

When you use the Parse method, Alteryx runs your full expression against the string, but it only outputs the parts of the string that match what's inside the parentheses. Each set of parentheses creates a new output column.

Let's look at a simple example.

A Beginner's Guide to Alteryx: How to Use Regular Expressions

This next section of the article demonstrates a classic use case: parsing the 4-digit extension from a ZIP code. It's a perfect first example of a marked group.

Read the section 'Example of Using RegEx in Alteryx' which covers the zip code example. Focus on how the expression -(\d{4}) works.

Let's break down that expression, -(\d{4}):

  • -: This matches the literal hyphen character. It's outside the parentheses, so it's required for the pattern to match, but it won't be part of the output.
  • (): These parentheses define our marked group. Whatever is matched inside them will be extracted.
  • \d: This is a special RegEx character class that matches any single digit (0-9).
  • {4}: This is a quantifier that means "match the preceding token exactly 4 times".

So, \d{4} means "exactly four digits". The full expression looks for a hyphen followed by exactly four digits and then extracts just those four digits.

Now, let's see this in action with a video demonstration.

Alteryx Advanced Training: 2-Hour Expert Course on Data Analysis using Alteryx

This video from Simon Sez IT demonstrates several methods of the RegEx tool. We will focus on the 'Parse' method example.

Watch the segment from 01:04:41 to 01:06:22. The instructor shows how to extract a telephone number from a longer string using the Parse method. Notice how the expression (\d{3}-\d{2}-\d{4}) captures the entire phone number pattern.


4. Building More Complex Expressions

Real-world data is rarely as clean as a ZIP code or a perfectly formatted phone number. Let's explore some more powerful RegEx syntax.

Syntax Description Example
. Matches any single character (except newline). a.c matches "abc", "a_c", "a2c".
\w Matches any "word" character (letters, numbers, underscore). \w+ matches "word" or "word123".
\s Matches any whitespace character (space, tab, newline). hello\sworld matches "hello world".
* Quantifier: matches the preceding token 0 or more times. ab*c matches "ac", "abc", "abbbc".
+ Quantifier: matches the preceding token 1 or more times. ab+c matches "abc", "abbc", but not "ac".
[ ] Character Set: matches any single character inside the brackets. [aeiou] matches any vowel.
[^ ] Negated Set: matches any character not inside the brackets. [^0-9] matches any non-digit.
\ Escape Character: treats a special character as a literal. \. matches a literal period.

Let's see how to combine these in a more advanced scenario.

A Beginner's Guide to Alteryx: How to Use Regular Expressions

The final part of this article provides a more complex example: parsing structured information from a block of text that resembles XML. It introduces concepts like character sets and escape characters.

Read the second half of the article, starting from the 'Sidenote' about XML data. Focus on how the expressions to parse the 'Book ID' (\w{2}\d{3}) and 'Description' ([A-Z][^.]*\.) are constructed.

This example of parsing the description is particularly useful. The expression ([A-Z][^.]*\.) looks for:

  • [A-Z]: A single uppercase letter to start the sentence.
  • [^.]*: Any character that is not a period, repeated zero or more times. This is how it captures the middle of the sentence.
  • \.: A literal period to end the sentence. The backslash \ is crucial here to "escape" the period, which otherwise is a special character meaning "any character".

5. Practice and Experimentation

RegEx can be tricky, and the best way to learn is by doing. Writing and testing expressions is an iterative process. A highly recommended free tool for this is Regex101.com. It allows you to paste your text, write an expression, and it provides a full explanation of what your expression is doing, highlighting the matches in real-time.

Text Parsing Guide

The Alteryx Community 'Text Parsing Guide' mentions this excellent external resource for practicing your RegEx skills.

Read the section 'External RegEx Resources' and make a note of Regex101.com. I encourage you to open it in another tab to use for the following exercise.

Your Turn: Practice Exercise

Imagine you have a field with the following text: "User 'jsmith' logged in from IP 192.168.1.100"

Your goal is to parse this into two separate fields: the username (jsmith) and the IP address (192.168.1.100).

Try to build the expression in Regex101.com. Here's a hint for your expression structure:

User '(<group 1>)' logged in from IP (<group 2>)

Think about what syntax you would use for <group 1> (the username) and <group 2> (the IP address).

Solution Breakdown:

  • Username: It's a series of word characters. \w+ is a good fit.
  • IP Address: It's a series of digits and periods. A simple way is to match any character . until the end of the string. But a more precise pattern would be [\d.]+, which matches one or more characters that are either a digit or a period.

So, a complete expression would be: User '(\w+)' logged in from IP ([\d\.]+)

In the Alteryx RegEx tool, you would:

  1. Put this expression in the editor.
  2. Set the output method to Parse.
  3. Two new output columns would be available to configure, one for the username and one for the IP address.

Conclusion

In this lesson, we introduced the fundamental concepts of Regular Expressions and their application in Alteryx. You are now equipped to tackle complex string parsing challenges that go far beyond basic string functions.

Here are the key takeaways:

  • Regular Expressions (RegEx) are patterns used to match and manage text.
  • The Alteryx RegEx tool is your primary interface for using RegEx, with Parse, Match, Replace, and Tokenize methods.
  • The Parse method relies on marked groups () to extract specific parts of a string into new columns.
  • Essential RegEx syntax includes character classes (\d, \w), quantifiers (+, *, {}), and character sets ([]).
  • External tools like Regex101.com are invaluable for building, testing, and debugging your expressions.

This is a topic where practice makes a significant difference. As you continue through the course, look for opportunities to apply RegEx to clean and structure messy text data.

In our next lesson, we will shift gears from parsing unstructured text to reshaping structured data, learning how to pivot data between wide and long formats using the Transpose and Cross Tab tools.