Skip to main content
SEARCH

Searches for a specific search string within a text and returns the index of the first occurrence

Updated over a week ago

Description

The SEARCH() function is used to locate the starting position of a specific search string within a given text. It returns the character position of the first occurrence of the search string, or -1 if no match is found. This function is useful for tasks like pattern recognition and data extraction.

Syntax

SEARCH(text, search)

Output

integer

Variables

  1. text: The input text string in which you want to search for the search string.

  2. search: The search string you want to find within the text.

The SEARCH() function is case-sensitive, meaning it will only search text that exactly matches the specified search string in terms of both character sequence and letter case. If you need case-insensitive search, you may consider using REGEX_SEARCH() to achieve the desired result.

When the SEARCH() function returns -1, it indicates that there is no matching occurrence of the specified regular expression pattern or offset within the given text.

For example, if a user is looking for specific data and SEARCH() function returns -1, they might conclude that the desired data is not present in the document.

Example

SEARCH(`Text`,"fox")

ID

Text

SEARCH

1

The quick brown fox jumps over a lazy dog.

17

2

Savant is an intelligent analytics tool.

βˆ’1

3

There are no matches in this text.

βˆ’1

Did this answer your question?