MATLAB: If I have file names listed in a readtable how to get it to extract part of the file name

file name extraction

So what I'm trying to do is extract part of a file name from a column in a readtable. I already have the specific column assigned to a variable but I'm trying to create a path which requires me to pull part of the filename. Here's an example:
This is one of several hundred file names.
SSSM 5 – 15Nov17_1152 – GE – right – 9.fantasy.tiff
I need:
15Nov17_1152
It is in the same place for all the files. I have looked at several previous questions but I am really new to coding and the all have underscores around there's. If someone could solve this example for me and explain (in simple terms)how to apply it to several hundred file names.

Best Answer

You have two options for extracting that data. The first is the simplest one. Since you said that that information always occurs at the same location, you can simply use fixed indices. Alternatively, you can use regexp to match your entry anywhere in the file.
For string x = 'SSSM 5 - 15Nov17_1152 - GE - right - 9.fantasy.tiff':
Option 1.
x(10:21) = '15Nov17_1152'
Option 2.
var = regexp(x,'\b(\d*\w*\d*_\d*)\b','match')
var{1} =
'15Nov17_1152'
The regular expression pattern matches digits, followed by a word characters, followed by digits, an underscore and finally more digits.