Function · Split and regex
Excel TEXTAFTER function
The Excel TEXTAFTER function returns the text after a delimiter. The last hyphen in 512-555-0148 leaves 0148.
Syntax =TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])
=TEXTAFTER("512-555-0148","-",-1)Arguments
| Name | Required | What to pass |
|---|---|---|
| text | Required | The text to cut. |
| delimiter | Required | The mark to start after. The mark itself is not included. |
| instance_num | Optional | Which occurrence. 1 is the first. -1 is the last. |
| match_mode | Optional | 0 is case-sensitive. 1 ignores case. |
| match_end | Optional | 1 lets the end of the text count as a delimiter. 0, the default, does not. |
| if_not_found | Optional | The fallback when the delimiter is missing. Otherwise a miss is #N/A. |
Examples
The last four digits of a hyphenated phone number
=TEXTAFTER(B1,"-",-1)Result 0148
| A | B | |
|---|---|---|
| 1 | Phone | 512-555-0148 |
| 2 | Last four | 0148 |
TEXTAFTER returns the characters after a delimiter. In 512-555-0148 the last hyphen is the one before 0148, so instance -1 returns 0148. Instance 1, the default, stops at the first hyphen and returns 555-0148. The leading zero stays, because the result is text. Convert it to a number and the zero disappears.
TEXTBEFORE is the matching cut in the other direction. A missing delimiter is #N/A. Excel 2021 and earlier do not have TEXTAFTER. RIGHT of four characters works for this particular phone pattern and fails as soon as the punctuation changes.