Regex resources for new and occasional users

3 May 2020

I first encountered regular expressions, or regex, when I was a user of the late lamented Yahoo Pipes around 10 years ago. This data manipulation tool had a 'regex' module that was very handy for removing or replacing strings of text that matched a particular pattern.

Since then, regex has made several guest appearances in my career. It has popped up in everything from Google Analytics to the proprietary data scraping software I use on a daily basis. Even Python, which I started learning recently, has a built-in regex module.

And while I am still no regex expert (or should I say 'regexpert'), it's true that a little regex knowledge goes a long way. In my day job, whenever I have a new starter looking to gain some technical skills, I encourage them to start with HTML, then some CSS, and then get their head around regex. Yes, really!

Here are the regex resources that I use and hopefully you will find useful too.

Regular-expressions.info

Don't be put off by the dated feel of this site: Regularexpressions.info is, in my opinion, the most useful regex resource out there. Those new to regex will find the in-depth tutorial enlightening; occasional users will benefit from the Quick Start and Quick Reference guides; and power users will probably gravitate to the full reference tables.

Regex101

Once you have written your regular expression, you will probably want to to test it. Which tool you use for this comes down to personal choice, and mine is Regex101. It's a free browser-based tool that doesn't require registration.

Enter your regular expression in the box at the top of the editor, and your test string (the text you want to search) in the box below; Regex101 will highlight any matches:

Regex101

What's more, a panel to the side will attempt to explain the expression in natural language - for example "\s matches any whitespace character". Just in case your expression works but you don't know why!

The built-in quick reference is also useful in that it not just lists regex tokens but gives an example of each - with an expression, a test string, and matches. For example:

Regex101 reference

Regex Numeric Range Generator

The Regex Numeric Range Generator may be a slightly niche resource but I have found it both useful and enlightening. It enables to create a regular expression that matches any number within a range of your choice. (For example if you choose a range between 100 and 200, the regex will match 100 and 150 but not 90 or 210).

In my day job, I use a scraping tool to scrape automotive listings and then use regex to extract the vehicle year. Previously I had been using an expression to match any four digit number (\d\d\d\d) but this tool enabled me to create an expression that would only match plausible year values. No more cars from the year 3000!

The other great thing about this tool is that it has an option to 'Show the Process Step by Step'. This opens a console that illustrates how to get from your minimum and maximum values to a regex pattern in three steps:

Numeric Range Generator console

Seeing this was like the proverbial lightbulb going off in my head. I have respect for any developer that takes the time not just to build useful tools but also let others see behind the curtain and learn something from doing so.

If you are just starting out with regex, or are long-time occasional user like me, I hope you have found this useful. I'll add to it as and when I can. But in the meantime, tell me: what do you use regex for and what tools and resources help you?

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
James Clark
Hi! I'm James Clark and this is my website. Need help with your own website's analytics, SEO, content or ads? Contact me
Copyright © James Clark
0
What do you think? Leave a commentx
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram