REGEX_SEARCH
Returns the index of the first character of the first matching substring based on a regular expression pattern
Description
The REGEX_SEARCH()
function is used to find and return the starting index of the first character of the first occurrence of a substring that matches a regular expression pattern within a given text. This function is particularly useful for locating specific patterns or positions within text data.
Syntax
REGEX_SEARCH(text
, pattern
, [offset])
text
: The input text string in which you want to search for a matching substring.pattern
: The regular expression pattern to search for within the text.offset: (Optional) An offset (number greater than 0) that specifies the occurrence of the matching substring to return. The default is usually the first occurrence (offset 1).
Example
Table
1
Contact us at (555) 555-1234 for support.
2
Please call 1-800-123-4567 for inquiries.
3
No phone number in this text.
Function
REGEX_SEARCH(`Text`, "[+]?[0-9]?[-. ]?\\(?[0-9]{3}\\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}")
Results
15
11
-1
Last updated