Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 用于删除隐藏字段的正则表达式_.net_Regex - Fatal编程技术网

.net 用于删除隐藏字段的正则表达式

.net 用于删除隐藏字段的正则表达式,.net,regex,.net,Regex,我编写了以下正则表达式来从html中删除viewstate隐藏字段 Regex.Replace(html, "<input[^>]*id=\"__VIEWSTATE\"[^>]*>", string.Empty, RegexOptions.IgnoreCase); Regex.Replace(html,“]*id=\”\uu VIEWSTATE\“[^>]*>”,string.Empty,RegexOptions.IgnoreCase); 我如何修改它以在正则表达式中

我编写了以下正则表达式来从html中删除viewstate隐藏字段

Regex.Replace(html, "<input[^>]*id=\"__VIEWSTATE\"[^>]*>", string.Empty, RegexOptions.IgnoreCase);
Regex.Replace(html,“]*id=\”\uu VIEWSTATE\“[^>]*>”,string.Empty,RegexOptions.IgnoreCase);
我如何修改它以在正则表达式中包含、\uuu EVENTTARGET、\uu EVENTARGUMENT、\uu EVENTVALIDATION?

Regex.Replace(html,“]*id=\”(\uu VIEWSTATE | uu EVENTTARGET | uu EVENTARGUMENT | uu EVENTVALIDATION)\“[^>]*>”,string.Empty,RegexOptions.IgnoreCase);
Regex.Replace(html, "<input[^>]*id=\"(__VIEWSTATE|__EVENTTARGET|__EVENTARGUMENT|__EVENTVALIDATION)\"[^>]*>", string.Empty, RegexOptions.IgnoreCase);
易于理解和扩展。

Regex.Replace(html,“]*id=\”(\uuuu-VIEWSTATE\uu-EVENTTARGET\uuuu-EVENTARGUMENT\u124;\uuu-EVENTVALIDATION)\“[^>]*>,string.Empty,RegexOptions.IgnoreCase);

易于理解和扩展。

您可以将所有项目添加到一个列表中,然后像下面这样迭代:

var items = new List { "__VIEWSTATE", "__EVENTTARGET", "__EVENTARGUMENT", "__EVENTVALIDATION" };

foreach (item in items) {
    Regex.Replace(html, string.format("<input[^>]*id=\"{0}\"[^>]*>", item), string.Empty, RegexOptions.IgnoreCase);
}
var items=新列表{“\uuuu VIEWSTATE”、“\uuuu EVENTTARGET”、“\uuuu EVENTARGUMENT”、“\uuuuu EVENTVALIDATION”};
foreach(项目中的项目){
Replace(html,string.format(“]*id=\“{0}\”[^>]*>”,item),string.Empty,RegexOptions.IgnoreCase);
}

如果我在代码中看到这段代码,我会发现它更容易理解,而不是一组OR'd语句。

您可以将所有项目添加到一个列表中,然后像这样迭代:

var items = new List { "__VIEWSTATE", "__EVENTTARGET", "__EVENTARGUMENT", "__EVENTVALIDATION" };

foreach (item in items) {
    Regex.Replace(html, string.format("<input[^>]*id=\"{0}\"[^>]*>", item), string.Empty, RegexOptions.IgnoreCase);
}
var items=新列表{“\uuuu VIEWSTATE”、“\uuuu EVENTTARGET”、“\uuuu EVENTARGUMENT”、“\uuuuu EVENTVALIDATION”};
foreach(项目中的项目){
Replace(html,string.format(“]*id=\“{0}\”[^>]*>”,item),string.Empty,RegexOptions.IgnoreCase);
}
如果我在代码中遇到这段代码,我会发现它更容易理解,而不是一组OR'd语句。

“]*id=\”\uuu(?:VIEWSTATE(?:EVENT(?:TARGET | ARGUMENT | VALIDATION))\“[^>]*>”
“]*id=\“\u(?:VIEWSTATE(?:EVENT(?:TARGET ARGUMENT | ARGUMENT VALIDATION))\”[^>>“