%% Detect File Extensions Using Patterns
% Since R2020b
% Create a string array of file and folder names, where some names have extensions.

str = ["abstract.docx","data.tar.gz","REPORTS"; ...
       "data-analysis.ppt","results.ptx","ARCHIVE"]

%
% To find names that end with extensions, create a pattern that matches a period followed by letters by using the lettersPattern function. (You can build up a complex pattern by combining simple patterns in expressions. Such expressions can also include literal text, like "." in this example.)

pat = "." + lettersPattern

%
% Return a logical array indicating which names end with extensions.

TF = endsWith(str,pat)

%
% Display the matching names.

str(TF)

%
% Find the names with extensions that are exactly three letters long.

pat = "." + lettersPattern(3);
TF = endsWith(str,pat);
str(TF)

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