c# - Get style attributes with regex from html string -


this html string:

<p style="opacity: 1; color: #000000; font-weight: bold; font-style: italic; text-decoration: line-through; background-color: #ffffff;">100 gram n!uts</p> 

i want font-weight value, if there one. how do regex?

this should solve it

(?<=font-weight: )[0-9a-za-z]+(?=;) 

explaination:

(?<=font-weight: ) string previous result has font-weight:

[0-9a-za-z]+ result contains letters , digits, @ least one

(?=;) first char after result ;

code:

string pattern = @"(?<=font-weight: )[0-9a-za-z]+(?=;)"; string value = "<p style=\"opacity: 1; color: #000000; font-weight: bold; font-style: italic; text-decoration: line-through; background-color: #ffffff;\">100 gram n!uts</p>"; string result = regex.match(value, pattern).value; //bold 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -