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.

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

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,...

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.