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.
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
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.
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.
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.
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:
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].
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.
This is a great way to get started using RegEx in Excel. The use cases and possibilities are only limited by your imagination.
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.
On the surface, Excel Checkboxes seem like a very simple feature - which is probably why they are often overlooked.
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.
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.
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.
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.
Curious about how ChatGPT can enhance your Excel experience? Here are some tips for using ChatGPT in Excel.
Most people use Excel solely as a tool for organizing data, but its versatility extends far beyond spreadsheets.
If you don't know how to create a family tree from scratch, these Microsoft Word and Excel templates can help you.
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.
You can calculate and visualize trends in Excel using the TREND function. Here's how to use the TREND function in Microsoft Excel.
How to fix the error of printing blank pages in Microsoft Excel. Why do some Excel documents not display data or contain blank pages when printed? Below are the reasons
How to pin Word, Excel and PowerPoint files to the corresponding app icon on the Windows 11 taskbar, How to pin Office files to the taskbar icon on Windows 11? Invite
How to fix the error of not being able to save an Excel file on Windows. If you can't save the Excel file, don't worry too much. Below are ways to fix the error of not being able to save the above Excel file
This article will guide you how to view CPU information, check CPU speed directly on your Chromebook.
If you don't want to sell or give away your old tablet, you can use it in 5 ways: as a high-quality photo frame, music player, e-book & magazine reader, housework assistant, and as a secondary screen.
You want to have a beautiful, shiny, healthy nail quickly. The simple tips for beautiful nails below will be useful for you.
This article will list color-inspired tips, shared by top designers from the Creative Market community, so you can get the perfect color combination every time.
Can you really replace your laptop with your phone? Yes, but you'll need the right accessories to turn your phone into a laptop.
One important thing in the full event video was that the upcoming ChatGPT app feature was demoed but no real details were shared. That is, ChatGPT's ability to see everything that's happening on the user's device screen.
Many top AIs, despite being trained to be honest, learn to deceive through training and systematically induce users into false beliefs, a new study finds.
ChatGPT now has a question change option so users can edit the question or content they are exchanging with ChatGPT.
QR codes seem pretty harmless until you scan a bad one and get something nasty thrown at you. If you want to keep your phone and data safe, there are a few ways you can spot a fake QR code.
On stage at MWC 2025, Qualcomm made a splash when it introduced its eighth generation of 5G modem called the X85, which is expected to be used in flagship smartphones launching later this year.
You have a trendy “Ultramarine” iPhone 16, but one fine day you suddenly feel bored with that color; what will you do?
In January, Microsoft announced plans to bring NPU-optimized versions of the DeepSeek-R1 model directly to Copilot+ computers running on Qualcomm Snapdragon X processors.
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.
Adding a spotlight behind your subject is a great way to separate your subject from the background. A spotlight can add depth to your portraits.
Outlook and other email services have limits on the size of email attachments. Here's how to increase the Outlook attachment size limit.