Case-Insensitive REGEXMATCH in Google Sheets (Partial or Whole)

Published on

In this post, I aim to shed some light on making a case-insensitive regular expression match using the REGEXMATCH function in Google Sheets.

Additionally, you will learn how to make only part of a regular expression case-sensitive.

As far as I know, REGEXMATCH (RE2 expressions) and QUERY are the functions that use regular expressions, especially for text matching. This post is about the former.

Notes:

  • In Google Sheets QUERY, we can use the MATCHES string comparison operator for a (preg) regular expression match.
  • Two more functions in Google Sheets use RE2 regular expressions: REGEXREPLACE and REGEXEXTRACT. Besides matching, they perform additional tasks.

What Is Case Sensitivity in Text Matching?

It’s all about whether the text is sensitive or insensitive to the capitalization of letters.

In other words, whether uppercase and lowercase letters are treated as distinct or equivalent.

Please see the table below.

Text 1Text 2Output (Sensitive to Capitalization)Output (Insensitive to Capitalization)
AppleAPPLEFALSETRUE
OrangeOrangeTRUETRUE
ORANGEAPPLEFALSEFALSE

I want to match the values in column 1 with the values in column 2 in two different ways.

I have done this, and the outputs in columns 3 and 4 are self-explanatory.

Case-Insensitive REGEXMATCH in Google Sheets (Whole)

Let’s start with the basic formulas first (whole matching). We will later discuss how to make only part of a regular expression case-sensitive in Google Sheets.

With the Help of Text Functions LOWER or UPPER

We usually use the text functions LOWER, UPPER, or PROPER for case-insensitive regex matching in Google Sheets. The idea is to change the case of the text to be tested and match the same case in the pattern.

Assume you have entered the text abCDef in cell A1 and inserted the following REGEXMATCH formula in cell B1:

=REGEXMATCH(A1, "abcdef")

It will return FALSE.

You can use the LOWER function as below for case-insensitive regex matching in Google Sheets:

=REGEXMATCH(LOWER(A1), "abcdef")

If the regular_expression is a cell reference, for example, B1, you should use LOWER(B1), UPPER(B1), or PROPER(B1) depending on A1’s letter case:

=REGEXMATCH(UPPER(A1), UPPER(B1))

With the Help of a Pattern Modifier

There is one drawback to using the LOWER/UPPER/PROPER text functions for case-insensitive regex matching in Google Sheets. What is it?

When using either of these two functions, we can’t make part of the REGEXMATCH regular expression case-sensitive.

In that scenario, the pattern modifier, i.e., (?i), does the job. We will come to that later.

First, learn about replacing the above ‘change case’ functions (UPPER/LOWER/PROPER) with the said pattern modifier.

This time, in B1, we can use the following formula:

=REGEXMATCH(A1, "(?i)abcdef")

We can follow this method when using cell references in both arguments:

=REGEXMATCH(A1, "(?i)" & B1)

Making Only Part of a Regular Expression Case-Sensitive in REGEXMATCH

The sample text in cell A4 is AppleORANge. How do I make part of this text, i.e., Apple, case-sensitive, and the other part, i.e., ORANge, case-insensitive?

You can use this formula in C4.

=REGEXMATCH(A4, "Apple(?i)orange(?-i)")

The text in cell A5 is Apple and ORANGE. To make the first part case-insensitive and the second part case-sensitive, use the following formula in cell C5:

=REGEXMATCH(A5, "(?i)(apple.*)(?-i)ORANGE")

The .* part matches any character zero or more times.

Case-Insensitive Regexmatch Formula - Part of Regular Expression

That’s all about case-insensitive REGEXMATCH in Google Sheets. You can find some related resources below.

Resources

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.

How to Perform Case-Sensitive XLOOKUP in Excel with EXACT

We may not always need to perform a case-sensitive XLOOKUP for product names in...

Filter the Last 7 Days in Excel Using the FILTER Function

You may have records spanning several days and want to filter the last 7...

Find Missing Dates in Excel

You can find missing dates in a list in Excel using either a VLOOKUP...

Generate Unique Random Numbers in Excel with Dynamic Arrays

Unique random numbers refer to random numbers without duplicates. Generating such numbers is straightforward...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

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.