Parse a string between two similar expression

3 ビュー (過去 30 日間)
KnowledgeSeeker
KnowledgeSeeker 2014 年 2 月 5 日
編集済み: per isakson 2014 年 2 月 6 日
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
  2 件のコメント
Matt Kindig
Matt Kindig 2014 年 2 月 5 日
Can you provide an example illustrating what you are trying to do?
KnowledgeSeeker
KnowledgeSeeker 2014 年 2 月 5 日
Thank you. I have edited my question

サインインしてコメントする。

回答 (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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by