MATLAB: Open Files by File Name Patterns

filter filesparsepatternsrecognize patterns

I am looking for the best Syntax to recognize patterns in file names and open the desired files/filter out unwanted files.
For example,
I have files named
HI_1C_TTTT4_468.xlsx
HI_2C_TTTT9_456.xlsx
HI_8C_TTTT7_279_Plot.xlsx
HI_5678_5487.xlsx
and I only wish to open the first two files, which have similar patterns unlike the last two. Any advice/examples?
Thank you!

Best Answer

regular expressions seem like the perfect candidate. In your case:
s = {'HI_1C_TTTT4_468.xlsx';
'HI_2C_TTTT9_456.xlsx';
'HI_8C_TTTT7_279_Plot.xlsx';
'HI_5678_5487.xlsx'}
ismatch = ~cellfun(@isempty, regexp(s, '^HI_\dC_TTTT\d_\d{3}\.xlsx$', 'match', 'once'))
is one way to do it.