Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
Asp.net 如何处理<;或>;在C#2.0中使用正则表达式的字符串类型_Asp.net_Regex_C# 2.0 - Fatal编程技术网

Asp.net 如何处理<;或>;在C#2.0中使用正则表达式的字符串类型

Asp.net 如何处理<;或>;在C#2.0中使用正则表达式的字符串类型,asp.net,regex,c#-2.0,Asp.net,Regex,C# 2.0,下面是用C#2.0编写的正则表达式,用于删除不需要的querystring(excludeList中存在的任何内容)的代码将从页面querystring中排除,它对我来说运行良好 string querystring = string.Empty; string excludeList = "cid,incid,h"; querystring = Regex.Replace(Regex.Replace(

下面是用C#2.0编写的正则表达式,用于删除不需要的querystring(excludeList中存在的任何内容)的代码将从页面querystring中排除,它对我来说运行良好

string querystring = string.Empty;                       
string excludeList = "cid,incid,h";                        
querystring = Regex.Replace(Regex.Replace(Regex.Replace(HttpContext.Current.Request.Url.Query, @"^\?", "&"), "&(" + excludeList.Replace(",", "|") + ")=[^&]*", "", RegexOptions.IgnoreCase), "^&", "?");
现在我想修改我的常规表达式,这样,如果我的excludeList包含如下内容,那么如果我的页面querystring中有<或>,我将进行编码

string excludeList = "cid,incid,h,<,>"; 

现在一切正常,我想用上面的正则表达式对“”进行编码。

试试这个

(?is)^(?<del>[^\?]+?)(?<retain>\?.+)$
(?is)^(?[^\?]+)(?\?。+)$
解释

@"
(?is)         # Match the remainder of the regex with the options: case insensitive (i); dot matches newline (s)
^             # Assert position at the beginning of the string
(?<del>       # Match the regular expression below and capture its match into backreference with name “del”
   [^\?]         # Match any character that is NOT a ? character
      +?            # Between one and unlimited times, as few times as possible, expanding as needed (lazy)
)
(?<retain>    # Match the regular expression below and capture its match into backreference with name “retain”
   \?            # Match the character “?” literally
   .             # Match any single character
      +             # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
$             # Assert position at the end of the string (or before the line break at the end of the string, if any)
"
@”
(?is)#将正则表达式的其余部分与选项匹配:不区分大小写(i);点匹配换行符(s)
^#在字符串开头断言位置
(?#匹配下面的正则表达式,并将其匹配捕获到名为“del”的backreference中
[^\?]#匹配任何非?字符的字符
+?#在一次和无限次之间,尽可能少的次数,根据需要扩展(懒惰)
)
(?#匹配下面的正则表达式,并将其匹配捕获到名为“retain”的backreference中
\?按字面意思匹配字符“?”
.#匹配任何单个字符
+#在一次和无限次之间,尽可能多次,根据需要回馈(贪婪)
)
$#在字符串末尾(或字符串末尾的换行符之前,如果有)断言位置
"
更新代码

string resultString = null;
try {
    resultString = Regex.Replace(subjectString, @"(?is)^(?<del>[^?]+?)(?<retain>\?.+)$", "${retain}");
} catch (ArgumentException ex) {
    // Syntax error in the regular expression
}
string resultString=null;
试一试{
resultString=Regex.Replace(subjectString,@“(?is)^(?[^?]+?)(?\?。+)$”,“${retain}”);
}捕获(参数异常){
//正则表达式中的语法错误
}

试试这个

(?is)^(?<del>[^\?]+?)(?<retain>\?.+)$
(?is)^(?[^\?]+)(?\?。+)$
解释

@"
(?is)         # Match the remainder of the regex with the options: case insensitive (i); dot matches newline (s)
^             # Assert position at the beginning of the string
(?<del>       # Match the regular expression below and capture its match into backreference with name “del”
   [^\?]         # Match any character that is NOT a ? character
      +?            # Between one and unlimited times, as few times as possible, expanding as needed (lazy)
)
(?<retain>    # Match the regular expression below and capture its match into backreference with name “retain”
   \?            # Match the character “?” literally
   .             # Match any single character
      +             # Between one and unlimited times, as many times as possible, giving back as needed (greedy)
)
$             # Assert position at the end of the string (or before the line break at the end of the string, if any)
"
@”
(?is)#将正则表达式的其余部分与选项匹配:不区分大小写(i);点匹配换行符(s)
^#在字符串开头断言位置
(?#匹配下面的正则表达式,并将其匹配捕获到名为“del”的backreference中
[^\?]#匹配任何非?字符的字符
+?#在一次和无限次之间,尽可能少的次数,根据需要扩展(懒惰)
)
(?#匹配下面的正则表达式,并将其匹配捕获到名为“retain”的backreference中
\?按字面意思匹配字符“?”
.#匹配任何单个字符
+#在一次和无限次之间,尽可能多次,根据需要回馈(贪婪)
)
$#在字符串末尾(或字符串末尾的换行符之前,如果有)断言位置
"
更新代码

string resultString = null;
try {
    resultString = Regex.Replace(subjectString, @"(?is)^(?<del>[^?]+?)(?<retain>\?.+)$", "${retain}");
} catch (ArgumentException ex) {
    // Syntax error in the regular expression
}
string resultString=null;
试一试{
resultString=Regex.Replace(subjectString,@“(?is)^(?[^?]+?)(?\?。+)$”,“${retain}”);
}捕获(参数异常){
//正则表达式中的语法错误
}

@如何在我现有的正则表达式中使用上述正则表达式,我想在我现有的正则表达式中添加,请建议如何处理的编码subjectString的值是多少,以及如何处理我现有的正则表达式以从querystring中删除querystring。请建议我看不到的编码处理,你的意思是我不必使用正则表达式,我应该使用你的正则表达式,并且在应用正则表达式之后,更新的值将如何存储回我的querystring变量更新了这个问题,请参阅编辑部分。我真的不明白您的解决方案中的WARE is编码处理,正如我所问的,<应转换为其适当的编码。。请建议我是否需要使用现有的正则表达式或仅使用您的正则表达式,但仍然不使用编码handling@how要在现有正则表达式中使用上述正则表达式,我想修改我现有的正则表达式,请建议如何处理的编码subjectString的值是多少,以及如何处理我现有的正则表达式以从querystring中删除querystring。请建议我看不到的编码处理,你的意思是我不必使用正则表达式,我应该使用你的正则表达式,并且在应用正则表达式之后,更新的值将如何存储回我的querystring变量更新了这个问题,请参阅编辑部分。我真的不明白您的解决方案中的WARE是编码处理,正如我所问的,<应转换为其适当的编码。。请建议我是否需要使用现有的正则表达式或仅使用您的正则表达式,但仍然没有编码处理