我目前拥有的正则表达式代码将查找与case完全匹配的代码,那么我必须做出哪些更改才能忽略这种情况?
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)));
}
答案 0 :(得分:6)
这应该有效:
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)), RegexOptions.IgnoreCase);
}
答案 1 :(得分:5)
(?i)
参数使正则表达式不区分大小写:
@"(?i)\b{0}\b"
请注意,\b
字边界仅在搜索字以字母数字字符开头和结尾时才有效。
答案 2 :(得分:0)
可以使用服务器端“(?i)
”,但这不适用于客户端。
我想它应该适合你,它会忽略这个案例。
即。 “...(?i)(jpg|jpeg|gif|png|wpf|...
”
希望它有所帮助。
答案 3 :(得分:0)
只需使用允许您指定选项的overload of Regex.IsMatch
:
return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)), RegexOptions.IgnoreCase);
答案 4 :(得分:0)
RegexOption.IgnoreCase应该是一个选项..
Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)), RegexOptions.IgnoreCase)