2015-03-25 18 views
0

我需要從.net類文件的html元素中獲取樣式。從類文件中讀取.net中的內聯樣式

<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"" />

輸出應該是

風格=「寬度:81px;高度:61px;填充頂:0像素;填充右:0像素;填充底:0像素; padding-left:0px; font-family:inherit; margin-top:0px; margin-right:10px; margin-bottom:0px; margin-left:0px;「

它會是如果通過正則表達式找到它會更好。

回答

0

嘗試用這個表達式:style="[^"]+"

Demo

0

可以使用style=".*?"正則表達式。

.*?將無匹配地匹配任何字符(因此,不會吃掉'src'屬性)。

C#代碼:

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;