TEXTBEFORE function in Google Sheets
Google Sheets doesn't have TEXTBEFORE — here's what does.
Google Sheets gets there with REGEXEXTRACT: a lazy pattern for the first occurrence, a greedy one for the last.
What TEXTBEFORE does in Excel
Returns text that occurs before a given character or string
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])Convert TEXTBEFORE formulas to Google Sheets
Before and after, formula by formula.
The username before the @:
Excel =TEXTBEFORE(A2, "@")Google Sheets =REGEXEXTRACT(A2, "^(.*?)@")The lazy (.*?) stops at the first @. INDEX(SPLIT(A2, "@"), 1) also works when the delimiter appears once.
Everything before the LAST slash:
Excel =TEXTBEFORE(A2, "/", -1)Google Sheets =REGEXEXTRACT(A2, "(.*)/")Regex is greedy, so (.*)/ captures up to the final slash.
Before the second dash, with a fallback when there is none:
Excel =TEXTBEFORE(A2, "-", 2, , , "n/a")Google Sheets =IFNA(REGEXEXTRACT(A2, "^((?:.*?-){1}.*?)-"), "n/a")REGEXEXTRACT returns #N/A when nothing matches, exactly like TEXTBEFORE — IFNA covers if_not_found.
Worth knowing
- Escape regex metacharacters in the delimiter: a dot is \., a pipe \|, a bracket \(. The Migration Assistant does this for you.
- For a case-insensitive match (match_mode 1), start the pattern with (?i).
Converting more than one formula? Formula Foundry's Migration Assistant scans every sheet in a workbook, fixes the formulas the Excel ↔ Sheets translator can convert, and flags every TEXTBEFORE it can't so none slip through silently.
More conversions to Google Sheets