MATLAB: How to get the date out of a filename using regexp

regexp

Currently, I have a list of files that are saved as the following 'xxx_2014_06_03_00_00_01'. I'd like to extract the date in the file name using regexp. Currently, my code is:
fdate=regexp(fList(i).name,'_/d+','once')
dt=datetime(fdate,'InputFormat','dd-MM-yyyy HH:mm:ss')
However, whenever I test it out, fdate is always returned as empty. I'm extremely confused about regexp and how to use it.
Thanks!

Best Answer

There are likely several ways to approach this. I would do it a bit differently:
str = 'xxx_2014_06_03_00_00_01';
fdate = regexp(str, '\d*','match');
datev = str2double(fdate);
dt=datetime(datev)
producing (here):
dt =
datetime
03-Jun-2014 00:00:01
I left these as separate lines to demonstrate how it works. The str2double call could be inserted into the datetime call.