MATLAB: Saving images with a new name extracted from the old image name

naming of images

Hi,
I want to process my images and then save the images with a new name. The new name of the images shall be extract from the image old name which is in the following format: '2019-03-14 11-15-49.498_CAM2_4_3.bmp'.
'2019-03-14' is the date, '11-15-49.498' is the time and 'CAM2_4_3' is the Camera and picutre number. I want to save the processed images in this format 11:15:49.498.bmp. I have 2000 images in the folder.
I created an expression which separate the hour, min and sec. But i have no clue how to save my images in this format. Here is my code:
%path to the images folder
fileFolder = fullfile('c:\','image_folder');
% Get a list of all files in the folder
filePattern = fullfile(fileFolder, '*.bmp');
theFiles = dir(filePattern);
fileNames = {theFiles.name}';
%number of images
nImages=length(theFiles);
for k = 1 : nImages
baseFileName = theFiles(k).name;
fullFileName = fullfile(fileFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
I1 = imread(fullFileName);
I2= imrotate(I1,90);
%Grouping the image name in hour, min and sec
expression= '\d{4}\-\d{2}-\d{2}\s(?<hour>\d{2})-(?<min>\d{2})-(?<sec>\d{2}\.\d{3})';
split=regexp(baseFileName,expression,'names');
h=split.hour;
m=split.min;
s=split.sec;
%path to output folder
outputFile = fullfile('output folder', h:m:s)
imwrite(I2, outputFile, 'bmp')
end
I know the code after path to output folder is wrong but i have no idea how to save my images in this format.

Best Answer

One possible way,
baseFileName = '2019-03-14 11-15-49.498_CAM2_4_3.bmp'; %for example
outputFileName = regexprep(baseFileName, '[0-9-]+ (\d+)-(\d+)-(\d+\.\d+).*', '$1:$2:$3.bmp')
Or, since you've already extracted the relevant data
outputFileName = sprintf('%s:%s:%s.bmp', h, m, s);