Skip commas in brackets regexp

6 visualizaciones (últimos 30 días)
Etienne
Etienne el 19 de Abr. de 2017
Comentada: Etienne el 21 de Abr. de 2017
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 comentario
Walter Roberson
Walter Roberson el 19 de Abr. de 2017
Is nesting of brackets permitted? If so that makes it much harder.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Abr. de 2017
S = 'A,VC,D,XO(12,13,14,15),DX,DY';
regexp(S,'\w+(\([^)]+\))?', 'match')
  4 comentarios
Walter Roberson
Walter Roberson el 20 de Abr. de 2017
regexp(str,'\w*([\(\[][^\)\]]*[\)\]])?', 'match')
appears to work for both this case and the previous case.
Etienne
Etienne el 21 de Abr. de 2017
Thanks :-)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by