Parse a string between two similar expression

3 次查看(过去 30 天)
I am writing a program that basically aim to parse the word between to similar expression and store a word in a cell array.
I want to use
regexp to math the two expression and only return and store the word in between the two expressions. any suggestions
[matchedExpression, parsedWord] = regexp (text, [& nbsp;'\w*' & nbsp;], 'split');
Example:
text= '$ nbsp;words& nbsp;'
I want to get the words
output= words
Thanx

回答(1 个)

per isakson
per isakson 2014-2-5
编辑:per isakson 2014-2-6
lookaround seems to suite your need.
text = '$ nbsp;words& nbsp;';
cac = regexp( text, '(?<=\$ nbsp;).+?(?=\& nbsp;)', 'match' );
returns {'words'}
If "words" stands for more than one word and you want to 'split' them, do that in a second step.

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by