Extracting pieces of string data
Show older comments
I have several hundred files where I need to take specific sections of a string from 3 different formats:
Here are the 3 formats:
A='2007011101_00001_00012_011914.new_1_I_CE_TH_J2.tif';
B='w2c1_00104_3_I_CE_TE_J2.tif';
C='center_20110_2_I_CE_FI_J.tif';
I need to save the part of the string before the (_1_) or (_2_) or (_3_)
So for A, I need: '2007011101_00001_00012_011914.new'
for B, I need: 'w2c1_00104'
for C, I need; 'center_20110'
Right now I am working on a solution using regexp, something along the lines of:
name=char(regexp(char(regexp(A,'\w+_1_','match')),'\w+','match'))
I haven't been able to come up with a way to identify and keep the multiple underscores and alphanumeric data that precede the (_1_)
Maybe I need to separate this functionality into 3 if statements to deal with the 3 different formats I am looking at?
Thank you for your help, Matlab Central is awesome!
Accepted Answer
More Answers (0)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!