Effacer les filtres
Effacer les filtres

Skip commas in brackets regexp

8 vues (au cours des 30 derniers jours)
Etienne
Etienne le 19 Avr 2017
Commenté : Etienne le 21 Avr 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 commentaire
Walter Roberson
Walter Roberson le 19 Avr 2017
Is nesting of brackets permitted? If so that makes it much harder.

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by