%% Extract File Name After Path Using Pattern
% Since R2020b
% Create a string array of file names, including full paths.

str = ["C:\Temp\MyReport.docx";
       "C:\Data\Experiment1\Trial1\Sample1.csv";
       "C:\Temp\Slides.pptx"]

%
% To extract the file names, first create a pattern that matches a full path, and then extract what comes after that pattern.
% A full path can have several levels, each consisting of any text followed by a "\" character. So start by creating a pattern that matches one level.

level = wildcardPattern + "\"

%
% Then, create a pattern that matches a full path, containing any number of levels.

pat = asManyOfPattern(level)

%
% Finally, call extractAfter.

filenames = extractAfter(str,pat)

%
% For a list of functions that create pattern objects, see pattern.
% Copyright 2020 The MathWorks, Inc.