%% Insert Text Before File Names 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"]

%
% Insert a new folder name at the end of each path, just before the file name. To match the file names, create a pattern that matches the last "\" character and all remaining text to the end of a string. Use the wildcardPattern function to match all characters except "\" and the textBoundary function to match the end of the string. Then call insertBefore to insert the new folder name before the matching text.

pat = "\" + wildcardPattern("Except","\") + textBoundary
filenames = insertBefore(str,pat,"\20200601")

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