A Useful Tool for Testing Regular Expressions

Regular expressions are exceedingly useful, but also exceedingly painful to write. For me, at least. The variety of matching options and their myriad combinations makes it difficult to remember what does what and trial-and-error can be difficult. That’s where RegExr, a powerful tool built by gskinner.com comes in.

gskinner.com's RegExr
gskinner.com’s RegExr

To use RegExr enter your regular expression in the field at the top and write some text which contains information you’re trying to match in the large field. If your regular expression matches text, it’ll be highlighted. You can also hover your mouse of your regular expression to see a description of what that character or set does. Additionally, you can use the provided samples on the right to quickly and easily build your regex.

In my case I was looking to identify various shipping carriers from their tracking numbers. On an ecommerce site I manage we’ve developed a tracking page where the user can simply enter the tracking number we sent them and track their package. The complication here is that we ship via USPS, UPS, and UPS Mail Innovations, all of which use varied tracking codes. In RegExr I wrote a list of various valid and invalid tracking numbers from each of the carriers and tested regular expressions to ensure they matched the correct tracking numbers (and only the correct tracking numbers). In a future post I’ll post the expressions I found or wrote for this purpose.

 

2 thoughts on “A Useful Tool for Testing Regular Expressions”

Leave a Reply