Skip commas in brackets regexp

조회 수: 5 (최근 30일)
Etienne
Etienne 2017년 4월 19일
댓글: Etienne 2017년 4월 21일
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.
Etienne
Etienne 2017년 4월 21일
Thanks :-)

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

추가 답변 (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