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 [email protected] 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 [email protected] and after we enter the above formula in cell C3, it will return [email protected].

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.

Sign up and earn $1000 a day ⋙

Leave a Comment

How to fix #SPILL! error in Microsoft Excel

How to fix #SPILL! error in Microsoft Excel

The #SPILL! error in Excel is quite common and it is quite simple to fix. Here is how to fix the #SPILL! error easily in Excel.

How to use the FILTER function in Excel

How to use the FILTER function in Excel

If you regularly work with data sets in Excel, you know how important it is to be able to quickly find the information you need.

What is the CORREL function in Excel?

What is the CORREL function in Excel?

Data can be overwhelming, but Excel's CORREL function helps you cut through the noise. Calculating the correlation coefficient is the secret weapon for uncovering hidden trends and making smarter decisions.

Difference between IF and Switch functions in Excel

Difference between IF and Switch functions in Excel

The IF statement is a common logical function in Excel. The SWITCH statement is less well known, but you can use it instead of the IF statement in some situations.

Why Checkbox is an underutilized Excel feature?

Why Checkbox is an underutilized Excel feature?

On the surface, Excel Checkboxes seem like a very simple feature - which is probably why they are often overlooked.

Why Excel is the only project management tool you need?

Why Excel is the only project management tool you need?

Many people have tried many project management tools, but still come back to Excel for project management. While it may not be perfect for everyone, it is a simple, yet effective solution that you already know how to use.

Valuable Excel shortcuts you should know

Valuable Excel shortcuts you should know

If you can master the formulas, shortcut keys on Excel will be much faster and more convenient. Let's join WebTech360 to collect for yourself the invaluable Excel shortcut keys in the summary below.

SUBTOTAL Function: Calculates the total value of a filtered list in Excel

SUBTOTAL Function: Calculates the total value of a filtered list in Excel

The sum function when filtering data is very important for Microsoft Excel users. This article will summarize for you how to filter and calculate sum in Excel using Subtotal.

How to Export Airtable to Excel and Google Sheets

How to Export Airtable to Excel and Google Sheets

Airtable lets you create and share relational databases easily. Export your Airtable data to Google Sheets or Excel to enjoy the benefits of advanced charts and data visualization.

Effective ways to use ChatGPT in Excel

Effective ways to use ChatGPT in Excel

Curious about how ChatGPT can enhance your Excel experience? Here are some tips for using ChatGPT in Excel.

8 Ways to Use Excel Beyond Spreadsheets

8 Ways to Use Excel Beyond Spreadsheets

Most people use Excel solely as a tool for organizing data, but its versatility extends far beyond spreadsheets.

The Best Free Family Tree Templates for Microsoft Word and Excel

The Best Free Family Tree Templates for Microsoft Word and Excel

If you don't know how to create a family tree from scratch, these Microsoft Word and Excel templates can help you.

Why are so many people stopping using Google Sheets and going back to Excel?

Why are so many people stopping using Google Sheets and going back to Excel?

For a while, Google Sheets lured people away from Excel. But many people came back after realizing that Google Sheets is far from beating Excel.

How to use the TREND function in Excel

How to use the TREND function in Excel

You can calculate and visualize trends in Excel using the TREND function. Here's how to use the TREND function in Microsoft Excel.

Top 5 best automatic home coffee makers

Top 5 best automatic home coffee makers

The automatic home coffee maker is a modern and professional product, bringing you and your family delicious cups of coffee with just a few quick steps.

Difference between regular TV and Smart TV

Difference between regular TV and Smart TV

Smart TVs have really taken the world by storm. With so many great features and the ability to connect to the Internet, technology has changed the way we watch TV.

Why doesnt the freezer have a light but the refrigerator does?

Why doesnt the freezer have a light but the refrigerator does?

Refrigerators are familiar appliances in families. Refrigerators usually have 2 compartments, the cool compartment is spacious and has a light that automatically turns on every time the user opens it, while the freezer compartment is narrow and has no light.

2 Ways to Fix Network Congestion That Slows Down Wi-Fi

2 Ways to Fix Network Congestion That Slows Down Wi-Fi

Wi-Fi networks are affected by many factors beyond routers, bandwidth, and interference, but there are some smart ways to boost your network.

How to Downgrade from iOS 17 to iOS 16 without Losing Data using Tenorshare Reiboot

How to Downgrade from iOS 17 to iOS 16 without Losing Data using Tenorshare Reiboot

If you want to go back to stable iOS 16 on your phone, here is the basic guide to uninstall iOS 17 and downgrade from iOS 17 to 16.

What happens to the body when you eat yogurt every day?

What happens to the body when you eat yogurt every day?

Yogurt is a great food. Is it good to eat yogurt every day? What will happen to your body when you eat yogurt every day? Let's find out together!

Which type of rice is best for health?

Which type of rice is best for health?

This article discusses the most nutritious types of rice and how to maximize the health benefits of whichever rice you choose.

How to wake up on time in the morning

How to wake up on time in the morning

Establishing a sleep schedule and bedtime routine, changing your alarm clock, and adjusting your diet are some of the measures that can help you sleep better and wake up on time in the morning.

Rent Please! Landlord Sim Tips for Beginners

Rent Please! Landlord Sim Tips for Beginners

Rent Please! Landlord Sim is a simulation mobile game on iOS and Android. You will play as a landlord of an apartment complex and start renting out an apartment with the goal of upgrading the interior of your apartments and getting them ready for rent.

Latest Bathroom Tower Defense Codes and How to Enter Codes

Latest Bathroom Tower Defense Codes and How to Enter Codes

Get Bathroom Tower Defense Roblox game codes and redeem them for exciting rewards. They will help you upgrade or unlock towers with higher damage.

Structure, symbols and operating principles of transformers

Structure, symbols and operating principles of transformers

Let's learn about the structure, symbols and operating principles of transformers in the most accurate way.

4 Ways AI Is Making Smart TVs Better

4 Ways AI Is Making Smart TVs Better

From better picture and sound quality to voice control and more, these AI-powered features are making smart TVs so much better!

Why ChatGPT is better than DeepSeek

Why ChatGPT is better than DeepSeek

DeepSeek initially had high hopes. As an AI chatbot marketed as a strong competitor to ChatGPT, it promised intelligent conversational capabilities and experiences.

Meet Fireflies.ai: The Free AI Secretary That Saves You Hours of Work

Meet Fireflies.ai: The Free AI Secretary That Saves You Hours of Work

It's easy to miss important details when you're jotting down other essentials, and trying to take notes while chatting can be distracting. Fireflies.ai is the solution.

How to raise Axolotl Minecraft, tame Minecraft Salamander

How to raise Axolotl Minecraft, tame Minecraft Salamander

Axolot Minecraft will be a great assistant for players when operating underwater if they know how to use them.