Regular expressions (regex) use specific character patterns to search and manipulate text. Writing these patterns can be difficult if you are not familiar with their syntax. Copilot in Excel can help you create regex formulas using simple text prompts. Let’s see how to use Copilot for Regex functions in Excel.
Key Takeaways:
- Regex patterns help you search and manipulate text in Excel.
- Copilot can create Regex formulas using simple prompts.
- REGEXTEST checks whether text matches a pattern.
- REGEXEXTRACT extracts text based on a pattern.
- REGEXREPLACE replaces text that matches a pattern.
Table of Contents
What is Regex?
A regular expression (regex) is a sequence of characters that defines a search pattern.
You can use regex to find specific text, extract information, and replace matching characters. Excel provides REGEX functions to extract, validate, and replace text using these patterns.
Common Regex functions
REGEXTEST
REGEXTEST checks whether text matches a specified regex pattern. It returns TRUE or FALSE.
Syntax:
= REGEXTEST(text, pattern, [match_case])
- text: The text string to be tested against the regular expression pattern.
- pattern: The regular expression pattern to match against the text.
- [match_case] (optional): A logical value indicating whether to consider case sensitivity (TRUE or FALSE).
REGEXEXTRACT
REGEXEXTRACT finds and extracts text that matches a regex pattern.
Syntax:
= REGEXEXTRACT(text, pattern, [match_number], [occurrence], [match_case])
- text: The text string from which to extract substrings.
- pattern: The regular expression pattern used to match substrings.
- [match_number] (optional): The index of the matching substring to extract (default is 1).
- [occurrence] (optional): The occurrence of the matching substring to extract (default is all occurrences).
- [match_case] (optional): A logical value indicating whether to consider case sensitivity (TRUE or FALSE).
REGEXREPLACE
REGEXREPLACE replaces text matching a regex pattern with the text you specify.
Syntax:
= REGEXREPLACE(text, pattern, replacement, [match_case])
- text: The text string in which to perform replacements.
- pattern: The regular expression pattern used to match text to be replaced.
- replacement: The text to replace the matched pattern.
- [match_case] (optional): A logical value indicating whether to consider case sensitivity (TRUE or FALSE).
How to Use Copilot for Regex Functions in Excel
REGEXTEST Formula
STEP 1: Open your Excel workbook and select the cell where you want to insert the formula.
STEP 2: Select the Copilot icon.
STEP 3: Enter a prompt describing what you want the formula to do. Include the cell reference and the pattern you want to check.
“Create a REGEXTEST formula to check whether the product code in cell A2 contains exactly three uppercase letters followed by four digits.”
STEP 4: Review the suggested formula. Ask Copilot to explain or modify the formula if required.
REGEXEXTRACT Formula
Use this prompt to extract an email address from the text string.
“Create a REGEXEXTRACT formula to extract the email address from the text in cell A2.”
REGEXREPLACE Formula
Use the prompt to remove unwanted characters from the list of phone numbers.
“Create a REGEXREPLACE formula to remove all non-numeric characters from the phone number in cell A2.”
Tips & Tricks
- Specify the exact characters, numbers, or text you want to match in the prompt.
- Make sure to mention which cell contains the source text.
- Explain whether you want to extract, replace, or validate text.
- If the Regex pattern is difficult to understand, ask Copilot to explain each symbol.
- Test the formula with a few different values before using it on the entire dataset.
FAQs
1. What is Regex in Excel?
Regex uses text patterns to search, extract, and replace data.
2. How to use Copilot for regex functions in Excel?
Copilot can suggest Regex formulas based on your prompts.
3. What are the three Regex functions in Excel?
The three Regex functions in Excel are REGEXTEST, REGEXEXTRACT, and REGEXREPLACE.
4. Can REGEXEXTRACT extract email addresses?
The REGEXEXTRACT function can extract email addresses using a suitable Regex pattern.
5. Can Copilot explain Regex patterns?
You can ask Copilot to explain each symbol in a Regex pattern.
John Michaloudis is a former accountant and finance analyst at General Electric, a Microsoft MVP since 2020, an Amazon #1 bestselling author of 4 Microsoft Excel books and teacher of Microsoft Excel & Office over at his flagship MyExcelOnline Academy Online Course.








