0

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 Answers 2

0

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

Demo

0

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.