Read specific string in a large text lines

1 view (last 30 days)
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?

Accepted Answer

Brian Hannan
Brian Hannan on 10 Aug 2017
Check out regexp. Something like
regexp(myString, 'Name>\w*</Name')
will do the trick.
  5 Comments
Praveen Choudhury
Praveen Choudhury on 10 Aug 2017
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 on 10 Aug 2017
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".

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!