I have lines in a text file like this
</TypeInfo><TypeMaxValue>65535</TypeMaxValue> <TypeMinValue>0</TypeMinValue><Name>Rick</Name>
How can I textscan and bring just
<Name>Rick</Name>
into my cell array?

 채택된 답변

Brian Hannan
Brian Hannan 2017년 8월 10일

0 개 추천

Check out regexp. Something like
regexp(myString, 'Name>\w*</Name')
will do the trick.

댓글 수: 5

Stephen23
Stephen23 2017년 8월 10일
Praveen Choudhury's "Answer" moved here:
It does not give me Rick as an answer.
Stephen23
Stephen23 2017년 8월 10일
편집: Stephen23 2017년 8월 10일
You need to add the 'match' argument (and alter the regular expression a little bit too):
>> regexp(S, '<Name>\w*</Name>','match')
ans = <Name>Rick</Name>
Thanks! It worked.
How can I extract a word where the word contains symbols, brackets as well as numbers?
See the attached of what I am talking. I am unable to extract the words in variable B.
Brian Hannan
Brian Hannan 2017년 8월 10일
Take a look at the regexp documentation for some ideas. There's an example over there that solves this problem. It's titled "Capture Substrings of Matches Using Ordinal Tokens".

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2017년 8월 10일

댓글:

2017년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by