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.

Microsoft 365 and Excel 2024, including Excel for the web. Also in Google Sheets. Excel 2021 and earlier do not have it.

Syntax =TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

TEXTAFTER
=TEXTAFTER("512-555-0148","-",-1)

Arguments

NameRequiredWhat to pass
textRequiredThe text to cut.
delimiterRequiredThe mark to start after. The mark itself is not included.
instance_numOptionalWhich occurrence. 1 is the first. -1 is the last.
match_modeOptional0 is case-sensitive. 1 ignores case.
match_endOptional1 lets the end of the text count as a delimiter. 0, the default, does not.
if_not_foundOptionalThe 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

=TEXTAFTER(B1,"-",-1)B2
Phone
AB
1Phone512-555-0148
2Last four0148
A picture of the sheet, not a live calculator.

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.