Cara menggunakan if regexmatch google sheets

Tips: Coba gunakan fungsi XMATCH baru, versi MATCH yang ditingkatkan yang bekerja ke arah mana saja dan mengembalikan kecocokan persis secara default, memudahkan dan lebih mudah digunakan daripada sebelumnya.

Fungsi MATCH mencari item yang ditentukan dalam rentang sel, kemudian mengembalikan posisi relatif item tersebut dalam rentang. Sebagai contoh, jika rentang A1:A3 berisi nilai 5, 25, dan 38, rumus =MATCH(25,A1:A3,0) akan mengembalikan angka 2, karena 25 merupakan item kedua dalam rentang tersebut.

Cara menggunakan if regexmatch google sheets

Tips: Gunakan MATCH ketimbang salah satu dari fungsi LOOKUP ketika Anda membutuhkan posisi sebuah item dalam rentang dan bukannya item itu sendiri. Misalnya, Anda mungkin menggunakan fungsi MATCH untuk menyediakan sebuah nilai untuk argumen row_num dari fungsi INDEX.

Sintaks

MATCH(lookup_value, lookup_array, [match_type])

Sintaks fungsi MATCH memiliki argumen berikut:

  • lookup_value    Diperlukan. Nilai yang ingin Anda cocokkan dalam lookup_array. Misalnya, saat Anda mencari nomor seseorang di buku telepon, Anda menggunakan nama orang tersebut sebagai nilai pencarian, tapi nomor telepon adalah nilai yang Anda inginkan.

    Argumen lookup_value bisa berupa nilai (angka, teks, atau nilai logika) atau referensi sel ke angka, teks atau nilai logis.

  • lookup_array    Diperlukan. Rentang sel yang dicari.

  • match_type    Opsional. Bilangan -1, 0, atau 1. Argumen match_type menentukan bagaimana Excel mencocokkan lookup_value dengan nilai dalam lookup_array. Nilai default untuk argumen ini adalah 1.

    Tabel berikut ini menjelaskan cara fungsi menemukan nilai berdasarkan pengaturan argumen match_type.

Match_type

Perilaku

1 atau dikosongkan

MATCH menemukan nilai terbesar yang lebih kecil dari atau sama dengan lookup_value. Nilai dalam argumen lookup_array harus disusun dalam urutan naik, misalnya: ...-2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE.

0

MATCH menemukan nilai pertama yang sama persis dengan lookup_value. Nilai dalam argumen lookup_array dapat disusun dalam urutan apa saja.

-1

MATCH menemukan nilai terkecil yang lebih besar dari atau sama dengan lookup_value. Nilai di argumen lookup_array harus diletakkan dalam urutan turun, misalnya: TRUE, FALSE, Z-A, ... 2, 1, 0, -1, -2, ..., dan sebagainya.

  • MATCH mengembalikan posisi nilai cocok dalam lookup_array, bukan nilai itu sendiri. Misalnya, MATCH("b",{"a","b","c"},0) mengembalikan 2, yang merupakan posisi relatif dari "b" dalam array {"a","b","c"}.

  • MATCH tidak membedakan antara huruf besar dan huruf kecil ketika mencocokkan nilai teks.

  • Jika MATCH tidak berhasil menemukan kecocokan, maka mengembalikan nilai kesalahan #N/A.

  • Jika match_type sama dengan 0 dan lookup_value berupa string teks, Anda dapat menggunakan karakter wildcard  — tanda tanya (?) dan tanda bintang (*) — dalam argumen lookup_value. Tanya tanya cocok dengan karakter tunggal apa pun, tanda bintang cocok dengan urutan karakter apa pun. Jika Anda ingin menemukan tanda tanya atau tanda bintang aktual, ketikkan tilde (~) sebelum karakter.

Contoh

Salin contoh data di dalam tabel berikut ini dan tempel ke dalam sel A lembar kerja Excel yang baru. Agar rumus menunjukkan hasil, pilih datanya, tekan F2, lalu tekan Enter. Jika perlu, Anda bisa menyesuaikan lebar kolom untuk melihat semua data.

Produk

Jumlah

Pisang

25

Jeruk

38

Apel

40

Pir

41

Rumus

Deskripsi

Hasil

=MATCH(39,B2:B5,1)

Karena tidak ada kecocokan persis, posisi nilai terendah berikutnya (38) di rentang B2:B5 dikembalikan.

Experience all of the benefits of the classic spreadsheet with much more powerful features that save users time!

  • One Click Data Imports From Anywhere
  • Transform Spreadsheets into Software in Seconds
  • Pre-built & Custom Templates
  • Visualize Real-Time Data in Centralized Dashboards

REGEXMATCH function is one of the most underrated functions of Google Sheets. Most users often choose not to use it as they think it’s probably going to be too complex.

The presence of regular expressions in the formula often puts people off.

However, with a little guidance, you can begin to incorporate the function into your spreadsheets and reap its benefits.

In this tutorial, I will cover how to use the REGEXMATCH function in Google Sheets and show you some simple examples that will further help you understand how to use it in your day-to-day work.

Table of Contents

What does the REGEXMATCH Function Do?

The REGEXMATCH function belongs to Google Sheets’ suite of REGEX functions along with functions like REGEXEXTRACT and REGEXREPLACE.

Its main task is to find if a string of text matches a regular expression.

The function returns a TRUE if the text matches the regular expression’s pattern and a FALSE if it doesn’t.

What is a Regular Expression (REGEX)?

A regular expression is a text pattern. It is a sequence of characters, including symbols, letters, and numbers that are combined to form a search string.

A regular expression is often characterized by certain special symbols, also known as ‘metacharacters’.

The metacharacters are meant to represent either a single character, a sequence of characters, or one of the characters in a set.

Here are some metacharacters that the REGEXMATCH function supports:

Metacharacter

What it Represents

^The beginning of the string$The end of the string.A single character?Zero or one occurrence of a character or string*Zero or more occurrences of a character or string+One or more occurrences of a character or string|The Or operator()This holds a group of metacharacters inside it and represents that sequence of characters[]This holds a set of characters and represents any one of the characters inside it[^]This holds a set of characters and represents any one of the characters not listed inside it\This is used to escape a special character

A regular expression containing a combination of these metacharacters, along with other alphanumeric and/or special characters can help you find specific characters, strings, or patterns in a text string.

For example, the regular expression ‘^gr(a|e)y$’ matches strings that start with ‘gr’ followed by either an ‘a’ or an ‘e’ and ends with a ‘y’.

Syntax of the REGEXMATCH Function

The syntax for the REGEXMATCH function is as follows:

REGEXMATCH(text, reg_exp)

Here,

  • text is the string or value to be tested for whether it matches the regular expression.
  • reg_exp is the regular expression the text is compared to.

Applications of the REGEXMATCH Function (Examples)

The REGEXMATCH function can be quite helpful when you want to search for the existence of a particular search string or pattern in the contents of a cell.

Here are some useful applications of the REGEXMATCH function:

  1. You can use it to identify cells in a range that contain a particular letter, word or phrase.
  2. You can use it to identify cells that start with or end with a particular character or group of characters.
  3. You can use it to find the exact match of a string.
  4. You can use it to go through a list of social media posts to identify posts that contain hashtags.
  5. You can use it to find or validate email addresses, credit card numbers, IDs, etc. or any other format

There are many other ways in which you can apply the REGEXMATCH function. Once you start getting comfortable with REGEXMATCH and regular expressions, you will find that the possibilities are endless.

Let us see how REGEXMATCH can be used in each of the above applications

Using the REGEXMATCH Function to Identify Cells that Contain a Letter, Word, or Phrase

Let’s first see how you can use REGEXMATCH to identify if a cell contains a specific letter, word, or phrase.

If you want to know if cell A1 contains the word “good” then use the REGEXMATCH function as follows:

=REGEXMATCH(A1,"good")

Cara menggunakan if regexmatch google sheets

If you want to know if cell A1 contains any of the words ‘good’ , ‘wonderful’ or ‘amazing’, then that’s easy too.

We know that the metacharacter ‘|’ represents an Or operation. So you need to use the REGEXMATCH with a regular expression as shown below:

=REGEXMATCH(A1, "good|wonderful|amazing")

Cara menggunakan if regexmatch google sheets

If you want to know if cell A1 contains numbers between 0-9, then you will need to use the square brackets as shown:

=REGEXMATCH(A1, "[0-9]")

In the below example, it returns FALSE and there’s no number in cell A1.

Cara menggunakan if regexmatch google sheets

In the below example, it returns TRUE, as there’s a number in cell A1.

Cara menggunakan if regexmatch google sheets

Using the REGEXMATCH Function to Identify Cells that Start or End with a Specific Text

If you want to know if cell A1 starts with the word ‘you’ or ‘You’, then you need to use the ‘^’ metacharacter( since it represents the beginning of a string) along with the ‘|’ metacharacter.

So the function you will need to use is:

=REGEXMATCH(A1, "^you|You")

Cara menggunakan if regexmatch google sheets

 

If you want to know if cell A1 ends with the word ‘you’ or ‘You’, then you need to use the ‘$’ metacharacter( since it represents the end of a string) along with the ‘|’ metacharacter.

So the function you will need to use is:

=REGEXMATCH(A1, "you|You$")

Cara menggunakan if regexmatch google sheets

If you want to know if cell A1 starts with ‘You’ and ends with ‘good’ then you need to use a combination of both ‘^’ and ‘$’ metacharacters:

=REGEXMATCH(A1, "^You[a-zA-Z ]+good$")

Cara menggunakan if regexmatch google sheets

 

Here, we added “[a-zA-Z ]+” in the middle to represent any number of alphabets, both in lower and upper case, in between the words ‘You’ and ‘great’.

Note that there is a space after the ‘Z’ too because we also want to allow spaces to be present in the sequence.

The ‘+’ sign represents any number of letters and/ or spaces.

Cara menggunakan if regexmatch google sheets

Using the REGEXMATCH Function to Find the Exact Match of a String

Let’s say you want to know if cell A1’s contents exactly match the string “you”

For this, all you need to do is use the REGEXMATCH function as follows:

=REGEXMATCH(A1,"^you$")

Cara menggunakan if regexmatch google sheets

We get a FALSE in the result shown above because cell A1 contains the word “you” but does not contain only the word “you”.

Using the REGEXMATCH Function to Identify Hashtags among Social Media Posts

Let us say you have a set of social media posts in different cells of a column and you want to identify only those posts with hashtags in them.

Cara menggunakan if regexmatch google sheets

For this, you will need to find if each cell has the character ‘#’ in it. So, you can perform the following steps:

  1. Select the cell you want to get your TRUE/FALSE result in (B1 in our example)
  2. Type the formula: =REGEXMATCH(A1,”#”). Don’t forget to put the regular expression within double-quotes.
  3. Press the return key.
  4. You should now see a TRUE or FALSE value indicating if the string in A1 has a hashtag or not.
    Cara menggunakan if regexmatch google sheets
  5. Double click on the fill handle of B1.
  6. You should now see the results for all the cells in the column.
    Cara menggunakan if regexmatch google sheets

Using the REGEXMATCH Function to Find Email Addresses in a Range

Let us see one final example of how powerful the REGEXMATCH function can be.

Cara menggunakan if regexmatch google sheets

Let us suppose you want to find all the cells in a range (shown in the image above) that contain email addresses.

For this, we first need to put together a regular expression for the pattern of an email address.

We know that:

  • Every email address starts with a string containing letters, numbers, dot operators. hyphens and/or underscores.
  • This should then be followed by an ‘@’ symbol.
  • This should be followed by another string containing letters and/ or numbers.
  • This should then be followed by a dot operator (.)
  • The email address should end with a string containing only letters.

For the above rules, we can formulate a regular expression as follows:

  • Every email address starts with a string containing letters, numbers, dot operators, hyphens, and/or underscores. So the regular expression can start with: ^[a-zA-Z0-9.-_]+.
  • This should then be followed by an ‘@’ symbol. So the expression can now be changed to ^[a-zA-Z0-9.-_]+@
  • This should be followed by another string containing letters and/ or numbers So the expression can now be changed to ^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+
  • This should then be followed by a dot operator (.). Since the dot operator might get mistaken for the dot metacharacter, we use a ‘\’ metacharacter to escape it. So the expression can now be changed to: ^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+\.
  • The email address should end with a string containing only letters. So the expression can now be changed to: ^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+\.[a-zA-Z]+$

Note: a-z represents any lowercase character, while A-Z represents any uppercase character. 0-9 represents any numeric character between 0 and 9. The plus metacharacter (+) specifies that there can be one or more occurrences of the characters mentioned within the square brackets [].

So our final regular expression can be:

^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+\.[a-zA-Z]+$

This is not perfect and completely foolproof, but to keep things simple, let’s go with it. It should work with our sample data.

Now let us put this to use in our sample dataset. Follow these steps:

  1. Select the cell you want to get your TRUE/FALSE result in (B2 in our example)
  2. Type the formula: =REGEXMATCH(A2,” ^[a-zA-Z0-9.-_]+@[a-zA-Z0-9]+\.[a-zA-Z]+$”). Don’t forget to put the regular expression within double quotes.
  3. Press the return key.
  4. You should now see a TRUE or FALSE value indicating if the string in A2 is an email address or not.
    Cara menggunakan if regexmatch google sheets
  5. Double click on the fill handle of B2.
  6. You should now see the results for all the cells in the column.
    Cara menggunakan if regexmatch google sheets

Now you can clearly see which of the cells contain email addresses.

Subsequently, you could use a filter to display only the cells that contain email addresses if required.

These were a few simple examples of how the REGEXMATCH function can save time and increase efficiency.

Points to Remember

Here are a few important points that you need to remember when using the REGEXMATCH function.

  • This function only works with text input. It does not work with numbers
  • If you want to use numbers as input (for example telephone numbers), you need to first convert it to text, using the TEXT function.
  • The REGEXMATCH function is case-sensitive. Therefore, you will need to specify the correct case inside the regular expression or convert the entire input string to upper or lower case using the UPPER or LOWER functions.

The REGEXMATCH function can have numerous applications, once you learn how to use it effectively.

Strong knowledge of regular expressions helps, and the best way to get a good hold over it is to practice.

Play around with different regular expressions and see what results you get.

You will be surprised by how useful the REGEXMATCH function can be once you start using it on your day-to-day spreadsheet data.

I hope you found this tutorial useful!

Other Google Sheets Tutorials you may find useful:

  • How to Use IMPORTRANGE Function in Google Sheets (Examples)
  • How to Use the INDIRECT function in Google Sheets
  • How to Compare Two Columns in Google Sheets (for Matches & Differences)
  • Remove the First Character from a String in Google Sheets
  • How to Scrape Websites Using Google Sheets Formulas (Examples)
  • RegexReplace Function in Google Sheets

Most Popular Posts

Cara menggunakan if regexmatch google sheets

5 Simple Ways to Highlight Duplicates in Google Sheets

Cara menggunakan if regexmatch google sheets

IF CONTAINS Google Sheets Formulas [2 Clever Options]

Cara menggunakan if regexmatch google sheets

How to Apply Formula to Entire Column in Google Sheets

Cara menggunakan if regexmatch google sheets

How to VLOOKUP From Another Sheet in Google Sheets

Sumit

Sumit is a Google Sheets and Microsoft Excel Expert. He provides spreadsheet training to corporates and has been awarded the prestigious Excel MVP award by Microsoft for his contributions in sharing his Excel knowledge and helping people.

1 thought on “REGEXMATCH Function in Google Sheets (Easy Examples)”

  1. Chet

    Hi this is wonderful tutorial thanks!. One thing I needed how to regex match and copy just that matched part into a new column cell, for example if the cell is an address containing a post/zip code and I wish to push that zip code into a new column cell beside it ? Is it even possible?