How can I test my RegEx?

by Débora Contente

I have used RegEx lots of times in Alteryx. It is a super useful resource, especially when web scraping! But it is not fun using the trial and error method to find the right expression when you have a workflow that takes more than 10 seconds to run! In this blog post, I will take you through my favourite ways of testing it before inputting it onto Alteryx.

Before continuing, If you have never heard of RegEx, there are several blog posts about it – Natalia just wrote one on it recently. Have a read and come back when you finish so that this post makes more sense.

Sublime Text

Sublime Text is a text editor that became my best friend when it comes to web scraping. I generally copy the underlying HTML onto it and then use their “RegEx Search” to test if my logic is working before applying it in Alteryx. That has saved me so much time!

How to access it

You can download it and learn more about it in here:
https://www.sublimetext.com/

How to do it

After downloading it and copying your HTML onto it (or any other text/data of course), you can either:

  • Click on Find in the menu bar at the top, followed by Find…
  • Use the shortcut Ctrl+F

That will result in the appearance of the following bar:

Then you just need to select the .* option and test your RegEx away!

Regex101

This one is even more helpful if you are in the beginnings of regex. Along with testing your expression, you will get an explanation of it and even Quick References that will remind you of what characters will mean what.

How to access it

This is an online resource – just access it on https://regex101.com/

How to do it

In my opinion, the interface is very user-friendly! Check the screenshot of it bellow and an explanation of each section.

This image has an empty alt attribute; its file name is image-24-1024x480.png
Regex101 interface

1 – Regular Expression – Use this section to write the expression you want to test.

2 – Test String – This is the section where you want to paste the data you want to test your expression on.

3 – Explanation – Here is something that Sublime Text will not give you – an explanation of the expression you are testing!

4 – Match information – The expression you are testing will highlight its matches in the Test String (2), but in this section, you will get all the matches and its correspondent character location!

5 – Quick Reference – You can think of this section as a “Help Guide”. Here you can refresh your memory of what will each expression match with!

I hope this was helpful in some way. Please do not hesitate on contacting me if you have any questions, feedback or suggestions for my next blog posts!

See you next time!