Regular Expressions in Tableau

regular expressions in tableau

Regular Expressions (shortened as REGEX or REGEXP) is a sequence of characters that specifies a match pattern in a text. Usually, such patterns are used by string-searching algorithms for ‘find’ or ‘find and replace’ operations on strings or for input validation.

A basic example of regular expression would be regex /c*t/ which would match “cat”, “cot”, or “cut”, but not “pat” or “but”.

Tableau offers four REGEX functions which include.

In this short article, I will be sharing three use cases of regular expressions in Tableau.

Case 1: Extracting email addresses from a string of text.

The regular expression pattern for email addresses is,

To demonstrate this, I have connected the following text data which contains customer email addresses - the goal here is to demonstrate how you can use REGEX functionality to extract the email addresses.

To extract the email addresses from this text data, I will create the following calculation.

using regular expressions to extract email addresses in Tableau

Note: The pattern in this calculation is enclosed in parentheses (capture group) - so Tableau can treat the multiple characters as a single unit.

Adding the calculation to the view.

(Which extracts each customer’s email address).

Case 2: Extracting a URL

The regular expression pattern for extracting URLs is,

Just like in the first case, you can extract URLs from text data using the following REGEX calculation.

using regular expressions <a href=to extracts URLs in Tableau" width="" height="" />

Note: The pattern in this calculation is enclosed in parentheses (capture group) - so Tableau can treat the multiple characters as a single unit.

Executing this calculation extracts the URLs from the text data.

Case 3: Extracting numbers from a string of text

Using Regular expressions, you can extract numbers from a string of text using the following calculation.

using regular expressions to extract numbers from a string of text data.

Note: The pattern in this calculation is enclosed in parentheses (capture group) - so Tableau can treat the multiple characters as a single unit.

Executing this calculation extracts the numbers from the text.

Conclusion

I hope this article was helpful to you. If you wish to receive more Tableau tips and tricks, kindly join our mailing list by subscribing below.

If you like the work we do and would like to work with us, drop us an email on our contacts page and we’ll reach out!