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
pat = pattern
Matching:
"." + lettersPattern
Return a logical array indicating which names end with extensions.
TF = endsWith(str,pat)
TF = 2x3 logical array
1 1 0
1 1 0
Display the matching names.
str(TF)
ans = 4x1 string
"abstract.docx"
"data-analysis.ppt"
"data.tar.gz"
"results.ptx"
Find the names with extensions that are exactly three letters long.
pat = "." + lettersPattern(3);
TF = endsWith(str,pat);
str(TF)
ans = 2x1 string
"data-analysis.ppt"
"results.ptx"
For a list of functions that create pattern objects, see pattern.