DEV Community

0xFedev
0xFedev

Posted on

1

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.

Environment

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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay