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 日

0 投票

S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')

4 件のコメント

Etienne
Etienne 2017 年 4 月 20 日
Thanks Walter. Works a treat.
Etienne
Etienne 2017 年 4 月 20 日
Hi Walter
I have to say that I am very confused by how regexp works. How would I split the following:
str = 'DATA,F,[11*0.D0,4.34255D0,-1.14281D0]'
to only split by the commas outside of the brackets?
Regards
Etienne
Walter Roberson
Walter Roberson 2017 年 4 月 20 日
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.
Etienne
Etienne 2017 年 4 月 21 日
Thanks :-)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

製品

質問済み:

2017 年 4 月 19 日

コメント済み:

2017 年 4 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by