Skip commas inside brackets when the expression has operators
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi all,
I am trying to split a string
"A(B,'C'),D(E,'F'),'==','G','H"
using strsplit so that I get these separately
A(B, 'C')
D(E, 'F')
'=='
'G'
'H'
Any help would be appreciated.
Dhanesh
답변 (2개)
Pravarthana P
2022년 4월 4일
Hi Dhanesh Kumar,
I understood that you are trying to split the string at commas except that within the brackets.
For example,
test = 'Ram,C,D,GH(cat,abc,6),,xyz';
regexp(test,'\w+(\([^)]+\))?', 'match')
Hope this helps you!!
댓글 수: 0
Xingwang Yong
2022년 4월 4일
expr1 = '(?<=\([^)]*),(?=.*\))'; % comma inside parenthesis, like '(..., ...)'
index_comma_in_paren = regexp(line, expr1);
Once I did this for my file exchange submission alignMatrix.m. Hope it helps.
댓글 수: 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!