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 = 2×3 logical array
1 1 0
1 1 0
Display the matching names.
str(TF)
ans = 4×1 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 = 2×1 string
"data-analysis.ppt"
"results.ptx"
For a list of functions that create pattern objects, see pattern.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.