Regular expression for 1*1 cell array

1 回表示 (過去 30 日間)
raghavendra kandukuri
raghavendra kandukuri 2019 年 11 月 12 日
コメント済み: Adam Danz 2019 年 11 月 12 日
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!

採用された回答

Adam Danz
Adam Danz 2019 年 11 月 12 日
編集済み: Adam Danz 2019 年 11 月 12 日
c = {'<string_attribute name="country"><s>CHINA5</s></string_attribute>'};
out = regexp(c, '(?<=name="country"><s>)(.*)(?=</s>)', 'match');
out{1}{1}
% ans =
% 'CHINA5'
  1 件のコメント
raghavendra kandukuri
raghavendra kandukuri 2019 年 11 月 12 日
Thank you @Adam

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2019 年 11 月 12 日
編集済み: Matt J 2019 年 11 月 12 日
c='<string_attribute name="country"><s>CHINA5</s></string_attribute>';
out=extractBetween(c,'<s>','</s>');
>> out{1}
ans =
'CHINA5'
  2 件のコメント
raghavendra kandukuri
raghavendra kandukuri 2019 年 11 月 12 日
Thank you @Matt
Adam Danz
Adam Danz 2019 年 11 月 12 日
This is definitley the better answer for r2016b and later.
I keep forgetting about that family of string functions introduced in that release.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by