0
votes

I need to fetch the style from a html element from .net class file.

<img alt="" style="width: 81px; height: 61px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: inherit; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px;" src=""https://www.google.co.in/images/srpr/logo11w.png"" />

output should be

style="width: 81px; height: 61px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: inherit; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px; "

it would be better if it is found through regex.

2

2 Answers

0
votes

Try with this regex: style="[^"]+"

Demo

0
votes

You can use style=".*?" regex.

.*? will match any character ungreedily (and thus, will not eat up 'src' attribute).

C# code:

 var input = "<img alt=\"\" style=\"width: 81px; height: 61px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: inherit; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 0px;\" src=\"\"https://www.google.co.in/images/srpr/logo11w.png\"\" />";
 var MyRegex = new Regex(@"style="".*?""");
 var result = MyRegex.Match(input).Value;