フィルターのクリア

Question on Regular Expressions (regexp)

1 回表示 (過去 30 日間)
Ashish Sheikh
Ashish Sheikh 2016 年 6 月 21 日
回答済み: Walter Roberson 2016 年 6 月 21 日
Hello ,
I need to extract some information from html data which is in string format.
mystr =
<html>
<head>
</head>
<body>
<div class="header">
MyProperty
</div>
<div class="content">
DefinedValue
</div>
<div class="header">
MyProp
</div>
<div class="content">
MyValueXYZ
</div>
<div class="header">
Get My result
</div>
<div class="content">
Mobile
</div>
</body>
</html>
Requirements :
  1. I should be able to access Content value upon giving header value as input..
  2. For example... If my header input is "My Property " , then regular expression should return "DefinedValue"
If my header input is "MyProp" , then regular expression should return corresponding content "MyvalueXYZ"
Can anyone help me out in developing the regular expression.????

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 6 月 21 日
LookFor = 'Myprop';
pattern = ['(?<=', LookFor, '.*?content">\s*)[^<]*' ];
extracted_content = regexp(mystr, pattern, 'match');

カテゴリ

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