Skip commas in brackets regexp
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Etienne
am 19 Apr. 2017
Kommentiert: Etienne
am 21 Apr. 2017
Hi All
I am trying to split a string, but need to skip strings within brackets, and keep this as one entity. How can I split the following
A,VC,D,XO(12,13,14,15),DX,DY
using strsplit, so that XO(12,13,14,15) is not split at the commas. I would therefore like to ignore the content inside the brackets.
Any help would be appreciated.
Etienne
1 Kommentar
Akzeptierte Antwort
Walter Roberson
am 19 Apr. 2017
S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')
4 Kommentare
Walter Roberson
am 20 Apr. 2017
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!