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
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.
Etienne
Etienne 2017년 4월 21일
Thanks :-)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters 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