Splitting the string using regular expression or string split

'a_bb_ccc_ddd_eeeeee_ffff_gg_h_i'
I have a string like this.
I need to split the string as
a_bb_ccc
ddd_eeeeeee
ffff_gg_h_i
how to use the regular expression or stringsplit in order to get the above output?

3 Kommentare

Could you please explain why the splitting points are where they are? It seems to be some of the underscores, but how to decide which ones?
i need to split after third underscore and then after fifth underscore

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 5 Mai 2015
s = 'a_bb_ccc_ddd_eeeeee_ffff_gg_h_i'
index = strfind(s, '_');
parts = {s(1:index(3)-1), s(index(3)+1:index(5)-1), s(index(5)+1:end)}

1 Kommentar

Thats great. Thanks a lot. is it possible to do with regular expression

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by