Match Two Columns that Contain Values Not in Any Order Using Regex

How do I match two columns that contain values not in any order in Google Sheets? I can suggest to you four different formulas using four different functions.

The functions include Vlookup, Countif, Query, and Regexmatch. Here I am going to use the Regexmatch function to match two columns that contain values not in any order in Google Sheets.

What about the other three functions. All that has already been covered and see that links.

1. Match two columns using the Vlookup function.

2. The Countif based formula to match columns.

3. The Query formula to compare and remove duplicates.

Here in this Google Sheets tutorial, I am going to detail you how to do it with the REGEXMATCH function.

Values in Order:

To compare two columns that in an order you can use the EQ Operator function or the equivalent ‘==’ operator. Everybody knows this.

In this comparison, the values should be from the same row but from two different columns.

values in order in two columns for comparison

Values Not in Order:

When you want to compare two columns and the values in that columns are not in any order, you can use any of the three formulas that I’ve mentioned above. Here is the fourth one that using Regexmatch.

values not in any order in two columns for comparison

If the column values are numeric, additionally you should use the To_Text function otherwise the Regex won’t work. Let me explain all these.

How to Match Two Columns that Contain Values Not in Any Order Using Regex in Google Sheets?

Regexmatch Formula to Compare Two Text Columns

=ArrayFormula(regexmatch(A1:A3, textjoin("|", 1, B1:B3)))

This formula is for the above range. If you want this formula to automatically adjust to the last nonblank row, use the IF and LEN combo as below with the formula above.

=ArrayFormula(if(Len(A1:A),regexmatch(A1:A, textjoin("|", 1, B1:B)),))

As you can see, the above formula uses the RE2 regular expressions to compare two columns that are not in any particular order.

How does this Regexmatch formula compare Columns?

Maybe you are interested to see the Regexmatch Syntext.

REGEXMATCH(text, regular_expression)

In this, the argument text is the values in Column A1: A. The regular expression is the Textjoin formula that joins the column B1: B values as below.

The Textjoin function in Regexmatch

The formula works like this. Just leave the above example aside.

Suppose I want to check the presence of either of the two strings (Japan or China) in A1. Here is the suitable Regexmatch formula.

=REGEXMATCH(A1, "Japan|China")

Now take a look at Cell E1 in the above image. I’ve combined the values in Colum B to use it as the regular expression in Query. Hope you could understand the Regexmatch logic above.

Regexmatch Formula to Compare Two Numeric Columns

You should feed text values to Regex as it’s text function. If you want to use Regex in columns containing numeric, date or time values, you should use the To_Text function to convert the numeric values to text values.

=ArrayFormula(if(Len(A1:A),regexmatch(to_text(A1:A), textjoin("|", 1, to_text(B1:B))),))

Just wrap the range with the To_text function to convert the numeric values to text. This way you can use Regexmatch with numeric columns.

Use Regex and match two columns in Google Sheets. Enjoy!

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.

Finding Most Frequent Text in Excel with Dynamic Array Formulas

Looking to identify the most frequently occurring text in Excel? You can do this...

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

How to Easily Repeat a Sequence of Numbers in Excel

Excel offers multiple ways to accomplish tasks, and the simplicity of each approach depends...

Create a Sequence of Dates at Every Nth Row in Excel (Dynamic Array)

Would you like to create a sequence of dates in every nth row in...

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.