Regular expression
Generating regular expression patterns drafts with GitHub Copilot
Last updated
Generating regular expression patterns drafts with GitHub Copilot
Last updated
Currently, LLMs do not have the ability to properly represent complex regular expressions. For complex ones, a human must provide supplemental input. On the other hand, it can be applied to simple regular expressions.
GitHub Copilot can create a draft of regular expression patterns. Below, we'll explain how to use regular expressions to search or extract strings. Two examples illustrate how GitHub Copilot can generate regular expressions through both input-output pattern and natural language pattern.
Sample Code
First, by writing the input and output, GitHub Copilot can create the regular expression pattern:
Sample Result
Second, by providing what you want to achieve with the regular expression in natural language:
Sample Code
Sample Result
Exercise 1: Extract only the lowercase letters from the string "Hello World."
Are the regular expression patterns extracting the exact matches from the given strings?
Currently, LLMs like GitHub Copilot do not have the ability to properly represent complex regular expressions. What would you do if you want to represent a complex regular expression? How would you leverage GitHub Copilot to support and assist you in building it?