How to Use Excels Regex Function to Power Up Your Searches

Filtering and searching in Excel is no easy task. Regex functions change that. Now you can specify exactly what you need—complex patterns, partial matches, or extracting structured data—without the effort.

Table of Contents

What is Regex?

Regex is a type of pattern used to search a string of text or characters for a match. Have you ever wondered how websites can tell you that the email pattern you entered on the login page is invalid? That's an example of a regex pattern using an email signature in action.

Regular expressions aren't unique to Excel — they're available in many text editors, programming languages, command-line tools, IDEs, and even Excel's competitor, Google Sheets .

Regex can seem complicated, and it can be if you want to use it to its full potential, but you don’t need to be a programmer to use it effectively. In some cases, you can get away with just knowing how to use a few basic symbols and patterns. This guide will keep it as simple as possible so you can get started.

The following are the symbols that will be used in this guide:

Symbol

Describe

-

Specify the range of characters in parentheses.

^

Matches the beginning of a string.

$

Matches the end of a string.

.

Matches any character except a newline character.

*

Matches zero or more preceding characters.

+

Matches the previous character or characters.

()

Group matching characters into one.

[]

Matches any character inside the brackets.

[^]

Matches any character not within the brackets.

{n}

Matches exactly n instances of the previous character.

{n,}

Matches n or more occurrences of the previous character

Simple regular expression patterns that you can build using these symbols include:

Regex Pattern

Describe

[0-9]

Matches a digit from 0 to 9

[a-zA-z0-9]

This is a range of matches that matches a single character from lowercase a to z, uppercase A to Z, and 0 to 9.

^pro

Matches any string starting with pro .

[^$]

Matches any character other than $ .

(child)

Subgroup sample .

a{3,}

Matches 3 or more occurrences of the part following a (for example, a , aa  , or aaa ).

Regex functions are predefined Excel formulas that can be used to define a pattern for searching and manipulating text strings. There are currently three regex functions. We will see how to use them individually and with other functions.

Search for patterns

The first function we'll look at is REGEXTEST. This function takes a text string that you want to use for searching and a regex pattern, then uses the latter pattern to find a match in the former pattern. The function will return True or False.

The syntax of the REGEXTEST function is as follows:

REGEXTEST(string_to_search, regex_pattern_to_use, [case_senstivity])

The first two parameters, string_to_search and regex_pattern_to_use, are self-explanatory. The [case_sensitivity] parameter is optional - anything in square brackets when talking about Excel syntax is optional - and indicates whether you want the search to be case sensitive (0) or case insensitive (1). The default is case sensitive.

The example will use REGEXTEST to see if the user entered a valid email address using the following formula:

REGEXTEST(B3, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$")

Here, we are searching in cell B3 to see if it contains an email address using the regular expression pattern below:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

If you put the formula in cell C3 and enter john.doe@example.com in cell B3, the formula will return True because it matches the email signature.

How to Use Excel's Regex Function to Power Up Your Searches
REGEXTEST function in Excel.

Additional data using Regex

Next, let's look at the REXEXEXTRACT function. This function returns a substring (a portion of a string) that matches the provided regex pattern.

The syntax of the REXEXEXTRACT function is as follows:

REGEXEXTRACT(string_to_search, regex_pattern_to_use, [return_mode], [case_senstivity])

Continuing with the email example, let's add a formula to cell B4 to extract the username of the email part.

The formula would look like this:

=REGEXEXTRACT(B3, "([^@]+)")

In this formula, we extract everything before the @ symbol in the email address entered in B3.

How to Use Excel's Regex Function to Power Up Your Searches
REGEXEXTRACT function in Excel.

Find and Replace with Regex

The last regex function we'll look at is REGEXREPLACE. This function is similar to Excel's REPLACE function, but it also supports RegEx. It takes the text string you want to modify and checks to see if any substrings match the specified regex pattern. If one is found, it replaces that string with the provided replacement string.

The syntax of the REGEXREPLACE function is as follows:

REGEXREPLACE(string_to_modify, regex_pattern_to_use, replacement_string, [number_of_occurrences], [case_senstivity])

Here are the important parameters to note in this function:

  • string_to_modify : The text string you want to modify.
  • replacement_string : String to replace the substring with.
  • number_of_occurrences : The exact instances you want to replace.

Here's an example of using the function to replace the username portion of an email with another text string:

=REGEXREPLACE(B3, "^[^@]+", "jane.doe")

The value of B3 is john.doe@example.com and after we enter the above formula in cell C3, it will return jane.doe@example.com.

How to Use Excel's Regex Function to Power Up Your Searches
REGEXREPLACE function in Excel.

Combining Regex with other functions

You can also combine regex functions with other functions in Excel. For example, you can combine the REGEXTEST function with Excel's IF statement and display appropriate messages based on the results.

Here is an example formula:

=IF(REGEXTEST(B3, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"), "This is a valid email address!", "The email address is invalid!")

This formula uses an IF statement to check if the email address entered in cell B6 is valid and then displays This is a valid email address! if it is TRUE or The email address is invalid! if it is FALSE . Additionally, you can pair this formula with the FIND function to quickly find data in Excel.

How to Use Excel's Regex Function to Power Up Your Searches
Combine the REGEXTEST function and the IF function in Excel.

This is a great way to get started using RegEx in Excel. The use cases and possibilities are only limited by your imagination.

Leave a Comment

Can Large Format Printing Ever Be Sustainable? The Answer Is Changing Fast

Can Large Format Printing Ever Be Sustainable? The Answer Is Changing Fast

Large format printing has long faced criticism for its environmental impact. Traditional substrates, solvent-based inks, and short-lived promotional campaigns have all contributed to the perception that eye-catching graphics come at a high environmental cost.

What Young Riders Should Know About Moving Their Motorcycles Across Cities

What Young Riders Should Know About Moving Their Motorcycles Across Cities

Long-distance travel can involve heavy traffic, changing weather conditions, and rider fatigue. If you are also dealing with the responsibilities of moving home, such as packing belongings or coordinating accommodation, a long ride may add unnecessary pressure to an already busy schedule.

Solving Microsoft Teams Shortcut Error Not Opening

Solving Microsoft Teams Shortcut Error Not Opening

Tired of Microsoft Teams shortcut error preventing you from opening the app? Follow our expert, step-by-step guide with the latest fixes for instant resolution. Works on Windows, Mac & web – no tech skills needed!

Solving Microsoft Teams Task Management Sync Error

Solving Microsoft Teams Task Management Sync Error

Tired of Microsoft Teams Task Management Sync Error halting your workflow? Follow our proven, step-by-step fixes to resolve sync issues fast and restore seamless task collaboration. No tech expertise needed!

Troubleshooting Microsoft Teams Wiki Error Formatting

Troubleshooting Microsoft Teams Wiki Error Formatting

Struggling with Microsoft Teams Wiki Error Formatting? This step-by-step guide reveals proven fixes for common wiki tab issues, ensuring smooth editing and collaboration in Teams. Get back to productive wikis fast!

How to Fix Microsoft Teams Installation Error for Linux

How to Fix Microsoft Teams Installation Error for Linux

Struggling with Microsoft Teams installation error on Linux? Discover step-by-step fixes for Ubuntu, Fedora & more. Resolve dependency issues, crashes, and errors quickly with our ultimate guide. Get Teams running smoothly today!

Solving Microsoft Teams Error Page Not Loading

Solving Microsoft Teams Error Page Not Loading

Struggling with Microsoft Teams "Error Page" not loading? Get step-by-step fixes for desktop, web, and mobile. Solve Microsoft Teams Error Page issues quickly and resume seamless teamwork today.

Solving Microsoft Teams Error Screenshot Issues

Solving Microsoft Teams Error Screenshot Issues

Tired of Microsoft Teams "Error Screenshot" blocking your workflow? Get proven, step-by-step solutions to resolve screenshot errors in Teams instantly and boost productivity. No tech skills needed!

How to Fix Microsoft Teams Error U User

How to Fix Microsoft Teams Error U User

Tired of Microsoft Teams "Error U" User blocking your chats? Get proven, step-by-step fixes to clear cache, reset, and restore seamless collaboration instantly.

Where are Microsoft Teams Registry Keys Located on Windows 11?

Where are Microsoft Teams Registry Keys Located on Windows 11?

Unlock the precise locations of Microsoft Teams registry keys on Windows 11. Step-by-step guide to find, access, and safely tweak them for optimal performance and troubleshooting. Essential for IT pros and Teams enthusiasts.