DEV Community


Posted on

Regular expressions are no longer a problem thanks to OpenAI!

Regular expressions, often shortened to "regex," are a powerful tool for pattern matching and text manipulation in programming. However, understanding and creating regular expressions can be a challenging task for many developers. This is where OpenAI comes in, by providing a way to explain regular expressions in a more intuitive and user-friendly way.


To try the potential of OpenAI, I will use Visual Studio Code and the VS ChatGPT extension.

Generating a regular expression

To ask OpenAI to generate a regular expression to check, for example, if a string is an email address, we write our requirement, select the text, and run command ChatGPT: Text completions. OpenAI will process our request and produce the regular expression, ready to use. Simple!

Generating a regular expression with VS ChatGPT

Explaining a regular expression

We are facing a regular expression and interpreting it might take a lot of time. OpenAI can help us!
By highlighting the regular expression and running command ChatGPT: Explain regular expression, we will ask OpenAI to produce the documentation of the expression!

Explaining a regular expression with VS ChatGPT

A more complex use case

Suppose we have a set of rules for which we have to generate the related regular expression. Can OpenAI help us? Let's find out together.
We highlight our rules and run command ChatGPT: Text completions. At the end of the processing, OpenAI will indicate the related regular expression. Well done!

complex regular expression with VS ChatGPT

Top comments (0)

Super Useful CSS Resources

A collection of 70 hand-picked, web-based tools which are actually useful.
Each will generate pure CSS without the need for JS or any external libraries.