Method Reference: string.extractAfter

string: newstr = extractAfter (str, pat)
string: newstr = extractAfter (str, pos)

Extract the substring after a position or pattern.

newstr = extractAfter (str, pat) returns, for each element of str, the part of the text that follows the first occurrence of pat, excluding pat itself. pat can be a string array, a character vector, or a cell array of character vectors, and must either be a scalar, applied to every element of str, or be of the same size as str and applied element-wise. If pat is not found in an element, the corresponding element of newstr is a missing value.

newstr = extractAfter (str, pos) returns the part of each element of str that follows the character position pos, that is, from pos+1 to the end. pos must be a positive integer that is either a scalar or the same size as str.

newstr is a string array of the same size as str. Missing values in str are preserved.

Source Code: string

Example: 1

extractAfter returns the part of each string after the first occurrence of a substring — for example the extension after the dot.

 files = string ({'cat.txt'; 'dog.csv'})
files =
  2x1 string array

    "cat.txt"    
    "dog.csv"
 extractAfter (files, '.')
ans =
  2x1 string array

    "txt"    
    "csv"