Read specific string in a large text lines

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?

 采纳的回答

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

5 个评论

Praveen Choudhury's "Answer" moved here:
It does not give me Rick as an answer.
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>
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.
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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by