HomeGoogle DocsSpreadsheetMatch Two Columns that Contain Values Not in Any Order Using Regex

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

Published on

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.

Convert Month Name to Days in Google Sheets

We can utilize the EOMONTH, MONTH, DATE, and DAY functions in Google Sheets to...

Creating Custom Descending Sequence Lists in Excel

You can utilize functions like ROW or SEQUENCE in Excel to create a custom...

SUMIFS with XLOOKUP in Excel and Google Sheets

SUMIFS and SUMIF are infamous for producing an "argument must be a range" error...

Counting XLOOKUP Results with COUNTIFS in Excel and Google Sheets

We can use COUNTIF or COUNTIFS alongside an XLOOKUP formula to conditionally count the...

More like this

Convert Month Name to Days in Google Sheets

We can utilize the EOMONTH, MONTH, DATE, and DAY functions in Google Sheets to...

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across 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.