Home » REGEXMATCH Function in Google Sheets (Easy Examples) Show
REGEXMATCH Function in Google Sheets (Easy Examples)REGEXMATCH function is one of the most underrated functions of Google Sheets. Most users often choose not to use it as they think its probably going to be too complex. The presence of regular expressions in the formula often puts people off. However, with a little guidance, you can begin to incorporate the function into your spreadsheets and reap its benefits. In this tutorial, I will cover how to use the REGEXMATCH function in Google Sheets and show you some simple examples that will further help you understand how to use it in your day-to-day work. Table of Contents
What does the REGEXMATCH Function Do?The REGEXMATCH function belongs to Google Sheets suite of REGEX functions along with functions like REGEXEXTRACT and REGEXREPLACE. Its main task is to find if a string of text matches a regular expression. The function returns a TRUE if the text matches the regular expressions pattern and a FALSE if it doesnt. What is a Regular Expression (REGEX)?A regular expression is a text pattern. It is a sequence of characters, including symbols, letters, and numbers that are combined to form a search string. A regular expression is often characterized by certain special symbols, also known as metacharacters. The metacharacters are meant to represent either a single character, a sequence of characters, or one of the characters in a set. Here are some metacharacters that the REGEXMATCH function supports: Metacharacter What it Represents A regular expression containing a combination of these metacharacters, along with other alphanumeric and/or special characters can help you find specific characters, strings, or patterns in a text string. For example, the regular expression ^gr(a|e)y$ matches strings that start with gr followed by either an a or an eand ends with a y. Syntax of the REGEXMATCH FunctionThe syntax for the REGEXMATCH function is as follows: REGEXMATCH(text, reg_exp)Here,
Applications of the REGEXMATCH Function (Examples)The REGEXMATCH function can be quite helpful when you want to search for the existence of a particular search string or pattern in the contents of a cell. Here are some useful applications of the REGEXMATCH function:
There are many other ways in which you can apply the REGEXMATCH function. Once you start getting comfortable with REGEXMATCH and regular expressions, you will find that the possibilities are endless. Let us see how REGEXMATCH can be used in each of the above applications Using the REGEXMATCH Function to Identify Cells that Contain a Letter, Word, or PhraseLets first see how you can use REGEXMATCH to identify if a cell contains a specific letter, word, or phrase. If you want to know if cell A1 contains the word good then use the REGEXMATCH function as follows: =REGEXMATCH(A1,"good")If you want to know if cell A1 contains any of the words good , wonderful or amazing, then thats easy too. We know that the metacharacter | represents an Or operation. So you need to use the REGEXMATCH with a regular expression as shown below: =REGEXMATCH(A1, "good|wonderful|amazing")If you want to know if cell A1 contains numbers between 0-9, then you will need to use the square brackets as shown: In the below example, it returns FALSE and theres no number in cell A1. In the below example, it returns TRUE, as theres a number in cell A1. Using the REGEXMATCH Function to Identify Cells that Start or End with a Specific TextIf you want to know if cell A1 starts with the word you or You, then you need to use the ^ metacharacter( since it represents the beginning of a string) along with the | metacharacter. So the function you will need to use is: =REGEXMATCH(A1, "^you|You")If you want to know if cell A1 ends with the word you or You, then you need to use the $ metacharacter( since it represents the end of a string) along with the | metacharacter. So the function you will need to use is: =REGEXMATCH(A1, "you|You$")If you want to know if cell A1 starts with You and ends with good then you need to use a combination of both ^ and $ metacharacters: =REGEXMATCH(A1, "^You[a-zA-Z ]+good$")Here, we added [a-zA-Z ]+ in the middle to represent any number of alphabets, both in lower and upper case, in between the words You and great. Note that there is a space after the Z too because we also want to allow spaces to be present in the sequence. The + sign represents any number of letters and/ or spaces. Using the REGEXMATCH Function to Find the Exact Match of a StringLets say you want to know if cell A1s contents exactly match the string you For this, all you need to do is use the REGEXMATCH function as follows: =REGEXMATCH(A1,"^you$")We get a FALSE in the result shown above because cell A1 contains the word you but does not contain only the word you. Using the REGEXMATCH Function to Identify Hashtags among Social Media PostsLet us say you have a set of social media posts in different cells of a column and you want to identify only those posts with hashtags in them. For this, you will need to find if each cell has the character # in it. So, you can perform the following steps:
Using the REGEXMATCH Function to Find Email Addresses in a RangeLet us see one final example of how powerful the REGEXMATCH function can be. Let us suppose you want to find all the cells in a range (shown in the image above) that contain email addresses. For this, we first need to put together a regular expression for the pattern of an email address. We know that:
For the above rules, we can formulate a regular expression as follows:
Note: a-z represents any lowercase character, while A-Z represents any uppercase character. 0-9 represents any numeric character between 0 and 9. The plus metacharacter (+) specifies that there can be one or more occurrences of the characters mentioned within the square brackets []. So our final regular expression can be: ^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+\.[a-zA-Z]+$This is not perfect and completely foolproof, but to keep things simple, lets go with it. It should work with our sample data. Now let us put this to use in our sample dataset. Follow these steps:
Now you can clearly see which of the cells contain email addresses. Subsequently, you could use a filter to display only the cells that contain email addresses if required. These were a few simple examples of how the REGEXMATCH function can save time and increase efficiency. Points to RememberHere are a few important points that you need to remember when using the REGEXMATCH function.
The REGEXMATCH function can have numerous applications, once you learn how to use it effectively. Strong knowledge of regular expressions helps, and the best way to get a good hold over it is to practice. Play around with different regular expressions and see what results you get. You will be surprised by how useful the REGEXMATCH function can be once you start using it on your day-to-day spreadsheet data. I hope you found this tutorial useful! Other Google Sheets Tutorials you may find useful:
Related posts:Convert Formulas to Values in Google Sheets (An Easy Guide) How to Multiply in Google Sheets (Numbers, Cells or Columns) Slow Google Sheets? 10 Easy Ways to Speed Up Google Sheets Web Scraping Simple Guide for 2022 SumitGoogle Sheets and Microsoft Excel Expert. Leave a Comment Cancel replyComment Name Email WebsiteSave my name, email, and website in this browser for the next time I comment.
Best Online Google Sheets CoursesBecome a Google Sheets expert today! View Course |