regexp split at first whitespace
33 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vincent Scalfani
am 14 Jul. 2018
Kommentiert: Simon
am 25 Apr. 2023
I have a cell dataset like this, where it is a string of letters and numbers all in one column (many rows):
data =
'0R 2 2 0'
'1R 2 0 0 4'
'2R 2 2 0 1 1 1'
'3R 2 2 2 1 1'
I would like to split each row into 2 columns at the first space:
data =
'0R' '2 2 0'
'1R' '2 0 0 4'
'2R' '2 2 0 1 1 1'
'3R' '2 2 2 1 1'
I tried:
splitcells = regexp(data, '\s+','split');
but that splits at each space, creating numerous columns, not 2. How do I get the regular expression to split only at the first space? Thanks
0 Kommentare
Akzeptierte Antwort
Paolo
am 14 Jul. 2018
You may use the once option to split only once at the first occurrence of whitespace.
splitcells = regexp(data,'\s','split','once')
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!