How to use regexp to extract data?

1 vue (au cours des 30 derniers jours)
Pete sherer
Pete sherer le 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

Réponse acceptée

Stephen23
Stephen23 le 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'

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by