日期:2014-05-17 浏览次数:20975 次
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTE5NDA1MDQ0Ng9kFgICAQ9kFgYCBQ8WAh4HVmlzaWJsZWhkAgcPFgIfAGhkAgkPFgIfAGhkZA==" />
</div>
string text = @"<div class=""aspNetHidden"">
<input type=""hidden"" name=""__VIEWSTATE"" id=""__VIEWSTATE"" value=""/wEPDwUKLTE5NDA1MDQ0Ng9kFgICAQ9kFgYCBQ8WAh4HVmlzaWJsZWhkAgcPFgIfAGhkAgkPFgIfAGhkZA=="" />
</div>";
string value = Regex.Match(text, @"(?i)<div[^>]*?class=(['""]?)aspNetHidden\1[^>]*?>\s*?<input[^>]*?value=(['""]?)(?<value>[^'""]*?)\2[^>]*?>\s*?</div>").Groups["value"].Value;
///wEPDwUKLTE5NDA1MDQ0Ng9kFgICAQ9kFgYCBQ8WAh4HVmlzaWJsZWhkAgcPFgIfAGhkAgkPFgIfAGhkZA==
string BaseString = @"<div class=""aspNetHidden"">\r\n<input type=""hidden"" name=""__VIEWSTATE"" id=""__VIEWSTATE"" value=""/wEPDwUKLTE5NDA1MDQ0Ng9kFgICAQ9kFgYCBQ8WAh4HVmlzaWJsZWhkAgcPFgIfAGhkAgkPFgIfAGhkZA=="" /></div>";
string pattern = @"<input type=""hidden"" name=""__VIEWSTATE"" id=""__VIEWSTATE"" value=""(?<MyValue>[^""]+)"" />";
Regex reg = new Regex(pattern, RegexOptions.IgnoreCase);
Match mac = reg.Match(BaseString);
string val = mac.Result("${MyValue}");