If you want to force the pattern matching to the beginning or the end of the filename, you should add a caret (^) or a dollar sign ($) respectively, for instance:
%// Match pattern at the beginning of the filename
tf = ~cellfun('isempty', regexp(file_names, '^.*\.mp4'));
%// Match pattern at the end of the filename
tf = ~cellfun('isempty', regexp(file_names, '\.mp4$'));
Alternative method (strfind)
If your search pattern is simple enough, you can use strfind instead:
Note that this method does not allow you to search for more complicated patterns, nor check conditions (trivially) such as the appearance of the pattern at the end of the string...
I would do that with
regexp
, like this:For example,
gives
Using regular expressions (regexp)
This can be easily achieved with
regexp
:If you want to force the pattern matching to the beginning or the end of the filename, you should add a caret (
^
) or a dollar sign ($
) respectively, for instance:Alternative method (strfind)
If your search pattern is simple enough, you can use
strfind
instead:Note that this method does not allow you to search for more complicated patterns, nor check conditions (trivially) such as the appearance of the pattern at the end of the string...