Skip commas in brackets regexp
조회 수: 10 (최근 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
2017년 4월 19일
S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')
댓글 수: 4
Walter Roberson
2017년 4월 20일
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!