MATLAB Answers

Skip commas in brackets regexp

13 views (last 30 days)
Etienne
Etienne on 19 Apr 2017
Commented: Etienne on 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 Comment
Walter Roberson
Walter Roberson on 19 Apr 2017
Is nesting of brackets permitted? If so that makes it much harder.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Apr 2017
S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')
  4 Comments

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!

Translated by