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
Post a Comment