The REGEXMATCH function in Google Sheets is a powerful tool used to identify whether a specific text string complies with a given regular expression pattern. This function serves as a critical asset for data validation, pattern recognition, and text processing within sheets.
Syntax
REGEXMATCH(text, regular_expression)
- text: The string of text you want to evaluate against the regex.
- regular_expression: The regex pattern that defines the criteria the text should match.
Example #1
=REGEXMATCH("Hello123", "^[A-Za-z]+[0-9]+$")
This function checks if “Hello123” consists of letters followed by numbers. The result is TRUE because it matches the pattern.
Example #2
=REGEXMATCH("test@example.com", "^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")
Here, the function evaluates the string “test@example.com” to see if it fits the standard email format. The result is TRUE as it conforms to the regular expression for valid emails.
Example #3
=REGEXMATCH("abc", "\d+")
This checks whether “abc” contains any digits. The result is FALSE since there are no digits in the string.
Error handling
- VALUE!: Returned when the text argument is not a valid string.
- N/A: This occurs if the regular_expression is not in proper regex format.
- ERROR!: Appear when there is an invalid reference in the function call, such as a missing argument.