Regular expression for 1*1 cell array

1 visualización (últimos 30 días)
raghavendra kandukuri
raghavendra kandukuri el 12 de Nov. de 2019
Comentada: Adam Danz el 12 de Nov. de 2019
Hello All,
I was trying to find the regular expression for a 1*1 cell array, the array looks somethig like this:
{'<string_attribute name="country"><s>CHINA5</s></string_attribute>'}
I need the country name string in above example, which is CHINA5, rest of the array would be same every time except the country string.
Any help is higley appreciated!

Respuesta aceptada

Adam Danz
Adam Danz el 12 de Nov. de 2019
Editada: Adam Danz el 12 de Nov. de 2019
c = {'<string_attribute name="country"><s>CHINA5</s></string_attribute>'};
out = regexp(c, '(?<=name="country"><s>)(.*)(?=</s>)', 'match');
out{1}{1}
% ans =
% 'CHINA5'

Más respuestas (1)

Matt J
Matt J el 12 de Nov. de 2019
Editada: Matt J el 12 de Nov. de 2019
c='<string_attribute name="country"><s>CHINA5</s></string_attribute>';
out=extractBetween(c,'<s>','</s>');
>> out{1}
ans =
'CHINA5'
  2 comentarios
raghavendra kandukuri
raghavendra kandukuri el 12 de Nov. de 2019
Thank you @Matt
Adam Danz
Adam Danz el 12 de Nov. de 2019
This is definitley the better answer for r2016b and later.
I keep forgetting about that family of string functions introduced in that release.

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by