HomeGoogle DocsSpreadsheetRegexmatch in Filter Criteria in Google Sheets

Regexmatch in Filter Criteria in Google Sheets [Examples]

Published on

You can use the Regexmatch in Filter Criteria in Google Sheets to apply more specific filter conditions. But you should take care when you use it in number as well as date columns as it’s a Text function.

If you use the Regexmatch to Filter a number column, format the column to text. You can use the Format menu for formatting number to text (Format > Number > Plain text).

Regarding the date criterion in Regex (Regex in a date column), I have another tutorial. You can find the link under the ‘Related Topics’ at the bottom.

We can learn how to use the Filter Function in combination with Regexmatch with the help of examples. I’ve seven example formulas for you that will take you through different Regex and Filter combinations.

Two must-read articles before further proceeding.

  1. How to Use REGEXMATCH Function in Google Sheets.
  2. How to Use the Filter Function in Google Sheets [Basic and Advanced Use].

Having said that, let’s move to our core part of this Google Sheets tutorial.

How to Use the Regexmatch in Combination with the Filter Function in Google Sheets

Sample Data to Use for Regex_Filter Combo.

Sample Data to Use for Regex_Filter Combo

Let’s learn how to use Regexmatch in Filter Criteria in Google Sheets by applying the filter to the above data, i.e. in column A.

Here are those 7 cool Regex Filter combo examples.

As you can see, our data comprise a list of different Virgin Oils and their prices. The first column contains the Virgin Oil Name. Let’s see how to apply different conditions in this column.

Similar: Multiple Conditions in Same Column Filtering in Google Sheets

Examples: Regexmatch in Filter Criteria in Google Sheets

1. Filter Column A contains all the word “Oil”, Case Sensitive.

=filter(A1:D, regexmatch(A1:A, "Oil"))

2. Filter Column A contains all the words “Olive Oil”, Case Sensitive.

=filter(A1:D, regexmatch(A1:A, "Olive Oil"))

3. Filter Column A for either Olive Oil or Coconut Oil, Case Sensitive

It’s multiple conditions in the same column in Filter Function.

=filter(A1:D, regexmatch(A1:A, "Olive Oil|Coconut Oil"))

4. Filter Column A when there is any word within the bracket that only we want to filter.

=filter(A1:D, regexmatch(A1:A, "\(([A-Za-z]+)\)"))

The output of this Filter Regex combo will be #N/A! as there is no such value in column A.

5. Regexmatch with Filter Function, Case Insensitive.

Here it’s a little tricky. You can apply any of the lower / upper/proper cases with Regexmatch regular expression.

Here I’ve used the small case and accordingly used the regular expression in the small case.

=filter(A1:D, regexmatch(lower(A1:A), "oil"))

Similar: How to Apply Bulk Change Case in Google Sheets Using Query Function.

6. How to filter a column based on 3 conditions in that same column using Regexmatch with the Filter function.

=filter(A1:D,regexmatch(A1:A, "Extra Virgin Olive Oil|Pure Virgin Canola Oil|Pure Rice Bran Oil"))

7. Filter Column A for Exact Match

Here no need to use Regex for the exact match. You can directly use the Filter function.

=filter(A1:D, A1:A="Oil")

That’s all for now. Use the above formulas on your own data to learn the use of it. Hope you have enjoyed the stay here.

Related Topics

  1. How to Use Regexextract Function in Google Sheets and RE2 Regular Expressions.
  2. Google Sheets Regexreplace Function How to and Examples.
  3. Regexmatch Dates in Google Sheets – Single/Multiple Match.
  4. REGEXMATCH in SUMIFS and Multiple Criteria Columns in Google Sheets.
  5. Use Query Function as an Alternative to Filter Function in Google Sheets.
  6. How to Use Date Criteria in Filter Function in Google Sheets.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

Excel Word Count: Beyond SUBSTITUTE

You might want to count the number of words in a cell in Excel...

Sum by Quarter in Excel: New and Efficient Techniques

Knowing how to sum by quarter is crucial in Excel because quarterly reporting has...

More like this

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

Count Distinct Values in Google Sheets Pivot Table

There is a built-in function for counting distinct values in a Google Sheets Pivot...

4 COMMENTS

  1. While the use of RegexMatch in the Filter is a very sleek way but I have observed that it fails if there is ( ) i.e. bracket in the comparison text strings.

    The possibility of such oversight increase if the comparison text is a formula. I am sure there must be a few more unacceptable characters.

    In such cases = i.e. equality operator works well for comparison.

    • Hi, S k Srivastava,

      You should escape such special characters using the \ (backslash).

      Eg:

      In cell D6 the string is “expert(sheets)”.

      To match this string we can use the following RegexMatch formula.

      =regexmatch(D6,"expert\(sheets\)")

      If you want to escape a backslash itself, then use the double backslash.

      Eg.

      String: expert\sheets\

      Formula:

      =regexmatch(D6,"expert\\sheets\\")

  2. The code is great, but be careful with the open- and closed-quotes if you’re copying and pasting. You’ll get a “formula parse error” if you copy the quotation marks directly. Instead, just delete the double-qoutes and enter them manually from your keyboard. Otherwise, good job!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.