
TEXTBEFORE
The TEXTBEFORE function returns a string value consisting of all characters that appear before a given substring in the original string value.
TEXTBEFORE(source-string, search-string, occurrence)
source-string: Any value.
search-string: The string value to search.
occurrence: An optional value indicating which occurrence of search-string within source-string to match (1 for first match, 2 for second match, …, -1 for last match, -2 for second to last match, …). If omitted, set to 1.
Notes
By default, if there are multiple occurrences of search-string in source-string, TEXTBEFORE returns the text up to (and excluding) the first occurrence.
If search-string isn’t found within source-string, or if the given occurrence can’t be found, an error is returned.
REGEX is permitted in search-string for more complex searches.
By default, the search isn't case sensitive. To consider case in your search, use the REGEX function for search-string.
Examples |
---|
=TEXTBEFORE("Marina Cavanna", " ") returns "Marina". =TEXTBEFORE("If you want to return the text before the second to, in case there are multiple to occurrences.", "to", 2) returns "If you want to return the text before the second." =TEXTBEFORE("All the text before the very last occurrence of the word the", "the", -1) returns "All the text before the very last occurrence of the word." =TEXTBEFORE("Get all the text before an email like marina@example.com", REGEX("([A-Z0-9a-z._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,4})")) returns "Get all the text before an email like ". =TEXTBEFORE("All the text before the table of contents"," ",3) returns “All the text”. |