Skip commas inside brackets when the expression has operators

4 visualizaciones (últimos 30 días)
Dhanesh Kumar A C
Dhanesh Kumar A C el 31 de Mzo. de 2022
Respondida: Xingwang Yong el 4 de Abr. de 2022
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

Respuestas (2)

Pravarthana P
Pravarthana P el 4 de Abr. de 2022
Hi Dhanesh Kumar,
I understood that you are trying to split the string at commas except that within the brackets.
The function “regexp can be used to match the expression and eliminate the commas:
For example,
test = 'Ram,C,D,GH(cat,abc,6),,xyz';
regexp(test,'\w+(\([^)]+\))?', 'match')
Reference link: Function "regexp"
Hope this helps you!!

Xingwang Yong
Xingwang Yong el 4 de Abr. de 2022
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.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by