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개)

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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by