Clear Filters
Clear Filters

How to use regexp to extract data?

1 view (last 30 days)
Pete sherer
Pete sherer on 23 Sep 2020
Answered: Stephen23 on 23 Sep 2020
Hi I have this cell array, and want to extract character before and after the "__"
tdata = {'XX__TG','GB_TH','BN__TH'}';
I want to use regexp and return me
out1 = {'XX'; 'GB'; 'BN'};
out2 = {'TG'; 'TH'; 'TH'};
Thanks

Accepted Answer

Stephen23
Stephen23 on 23 Sep 2020
>> tdata = {'XX__TG';'GB_TH';'BN__TH'};
>> spl = regexp(tdata,'_+','split');
>> spl = vertcat(spl{:});
>> out1 = spl(:,1)
out1 =
'XX'
'GB'
'BN'
>> out2 = spl(:,2)
out2 =
'TG'
'TH'
'TH'

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!