How to practice regular expressions more intuitively

This post contains some useful tools that are of great help to beginning users of regular expressions.

What is Regular expression?

Regular expressions (shortened as regex or regexp) are a special way of writing patterns that help you search for specific words or phrases in text. It’s like having a secret code that tells your computer exactly what to look for. This can be really helpful when you need to find something specific, like all the words that start with “cat” in a long story. Regular expressions make it easier and faster to find what you’re looking for!

Intuitive practice of regular expressions

As a mediocre corpus and python user, Regular expression indeed helps me do string searching more efficiently. But at the same time, I found that using regex sometimes is cumbersome, because:

  1. I might don’t remember what the search pattern means. In traditional regex teaching class, you probably hear your teacher says, “$ mataches the ending position of the string; [^]matches a character that is not included in the bracket”. But even with examples, this explanation doesn’t help us too much. We probably will forget them after the class.
  2. I’m not sure if there’s any errors in my regex. Only after I hit the search button and nothing retrieved, I realize there may be some errors. What’s worse, I don’t know where the errors are.

These problems push me to find some tools to help me learn regex, more intuitively. Then, Regulex got my attention.

Regulex is a JavaScript Regular Expression Parser & Visualizer. It can not only visualize the search pattern instantly, but also spot the possible errors.

Here is a sneak peek at the graph of Regulex:

Now, there is yet another feature I would love to see in Regulex. That is, I want to see the results retrieved from real data instantly after I type the pattern. Unfortunately, this tool doesn’t support it. But I found another tool that can meet the needs: Expressions.

Expressions is a Mac App with which you can have a live preview of what you write. The only downside of this app is that it’s commercial. But if you happen to have Setapp subscription, you can download it for free.

image.png


(Update: March 29th, 2023)

Game-changing way of playing around with regular expressions

I just found this tool called Regex.ai (credit:小众软件 Appinn ). It is a regex tool powered by AI. With it, we don’t have to remember the meaning and function of each symbol (or metacharacter). The only thing we do is to “insert your text and drag the cursor to highlight multiple strings to find matching regular expression.” In other words, we only need to select the part of string we want to match, then this AI tool will help us write the regular expression.

Please watch the demo video below to better understand this tool.

Gang Yao
Gang Yao
Lecturer

My research interests include corpus linguistics, Spanish as a Foreign Language, and academic discourse.

Related