Google Sheets Function: REGEXMATCH (2/3)

Quantity of Each Character

Quantifiers specify how many times the same character can appear. To specify a quantity or a range, add {} after the concerned character.


For example:

The regex "composer{0,}" checks here if the text contains this word with none, one or multiple "r":

google sheets function regexmatch character class quantity 2

There are also 3 shortcuts for quantifying a character:

The regex "composer*" is thus identical to the previous one "composer{0,}":

google sheets function regexmatch character class quantifier 2

Testing a Structure

To test if the structure of a text (like a reference, phone number, URL, etc.) matches what is expected, you will need to use several elements seen so far in a single expression.

For example, to validate the regex "^SP-[0-9]{3}-" the text must:

google sheets function regexmatch ref 2

Special Characters

Metacharacters are special characters with a specific role (you're already familiar with ^ $ [ ] | ? * + { }).

To negate the effect of a metacharacter and treat it as a simple character, precede it with a \ (except when the metacharacter is within a character class).

Thanks to \, the regex " \?$" can check if the text ends with " ?":

google sheets function regexmatch backslash 2
The metacharacters are \ ^ $ . [ ] | ( ) ? * + { }.
Additionally, note that \t stands for a tabulation, \r for a carriage return, and \n for a newline.

Class Shortcuts

As you now know, character classes define which characters are allowed or not. There are some practical shortcuts to simplify this:

The regex "^[A-Z]{2}.\w{3}$" verifies here if the text starts with 2 characters from the A-Z range, followed by any character (except newline), followed (and ending with) 3 alphanumeric characters:

google sheets function regexmatch class shortcuts 2

Case-Insensitive Search

To search for the word "sheets" without considering uppercase or lowercase, add (?i) at the beginning of the regex "(?i)sheets":

google sheets function regexmatch case insensitive 2