
Split and Extract Text with TEXTSPLIT, TEXTBEFORE, and TEXTAFTER (Delimiters, Patterns, and Nth Instances)
“Only the domain from an email address,” “an address split into city, district, and neighborhood,” or “each block from SKU-123-456” — solve it with a one-line formula using TEXTSPLIT/BEFORE/AFTER.
Syntax & Options
| Function | Syntax | Key Options |
|---|---|---|
| TEXTBEFORE | =TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]) | instance_num: split before the Nth instance; negative values search from the end. Use match_end to match the end of the text. |
| TEXTAFTER | =TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]) | instance_num: extract after the Nth instance; match_mode=1 ignores case. |
| TEXTSPLIT | =TEXTSPLIT(text, [col_delim], [row_delim], [ignore_empty], [match_mode], [pad_with]) | Supports arrays of multiple delimiters; use pad_with to fill missing values. |
Tip: For multiple delimiters, pass an array such as {"-","/","_"}. For spacing issues, clean the text first with TRIM.
TEXTBEFORE/AFTER — Extract Before or After
Email username/domain
=TEXTBEFORE(A2,"@")
=TEXTAFTER(A2,"@")
File name from a file path (after the last )
=TEXTAFTER(A2,"",-1)
Middle block from SKU-123-456
=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")
TEXTSPLIT — Split with Multiple Delimiters
Contact information with commas and semicolons
=TEXTSPLIT(TRIM(A2), {",",";"," "},, TRUE)
Split into rows and columns at the same time (address)
=TEXTSPLIT(A2, ", ", CHAR(10)) // Columns: commas; rows: line breaks
Pad missing values with 0
=TEXTSPLIT(A2, ",",, , , 0)
12 Practical Patterns
① Split search terms for an AND filter
=LET(k, TEXTSPLIT(LOWER($H$2)," "), FILTER(A2:A100, BYROW(A2:A100, LAMBDA(r, SUM(--ISNUMBER(SEARCH(k, LOWER(r))))=ROWS(k)))))
② Split names (English Last, First)
=TEXTSPLIT(A2, ", ") // {Last, First}
③ Standardize phone numbers
=TEXTJOIN("-",, TEXTSPLIT(SUBSTITUTE(A2," ",""), {"-","."}))
④ Parse a log key=value pair into two columns
=TEXTSPLIT(A2, "=",, TRUE)
⑤ File extension after the last period (.)
=TEXTAFTER(A2,".",-1)
⑥ Nth word
=INDEX(TEXTSPLIT(TRIM(A2)," "), N)
⑦ Split an address into city, district, and neighborhood
=TEXTSPLIT(SUBSTITUTE(A2," "," "), " ") // Clean up double spaces, then split
⑧ Split CSV data in one cell into rows and columns
=TEXTSPLIT(A2, ",", CHAR(10), TRUE)
⑨ Spill categories/tags into rows, then summarize
=LET(t, TEXTSPLIT(A2, ","), MAP(UNIQUE(t), LAMBDA(u, SUM(--(TRIM(t)=TRIM(u))))))
⑩ Domain and query from a URL
=TEXTBEFORE(TEXTAFTER(A2,"//"),"/")
=TEXTAFTER(A2,"?")
⑪ Remove nonbreaking spaces (CHAR(160)), then split
=TEXTSPLIT(SUBSTITUTE(A2,CHAR(160)," "), " ",, TRUE)
⑫ Display a helpful message if it fails
=IFERROR(TEXTAFTER(A2,"@"), "No domain")
Spill, Exceptions, and Performance Checks
- #SPILL! → Clear the spill range and start outside an Excel table.
- Consecutive delimiters → Use
ignore_empty=TRUEor normalize withSUBSTITUTE. - Case and accents → Standardize with
LOWER/UPPERbefore splitting. - Performance → Cache repeated preprocessing with
LETand use precise ranges instead of entire columns.
Summary
| Goal | Typical Formula |
|---|---|
| Extract before/after | TEXTBEFORE(text, delim) / TEXTAFTER(text, delim) |
| Split with multiple delimiters | TEXTSPLIT(text, {"-","/","_"}) |
| Nth or last instance | Use positive or negative instance_num values |
| Handle missing values/failures | IFERROR(...,"Not found"), pad_with |