Skip commas in brackets regexp

6 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2017-4-19
Is nesting of brackets permitted? If so that makes it much harder.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-4-19
S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')
  4 个评论
Walter Roberson
Walter Roberson 2017-4-20
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by