我目前拥有的regex代码将寻找与case完全匹配的代码,因此我必须做出哪些更改才能忽略case?
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"b{0}b", Regex.Escape(match)));
}
应该可以:
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"b{0}b", Regex.Escape(match)), RegexOptions.IgnoreCase);
}
(?i)
参数使正则表达式不区分大小写:
@"(?i)b{0}b"
请注意,b
词边界仅在搜索词以字母数字字符开始和结束时才有效。
服务器端," (?i)
"可以使用,但这不能在客户端工作。我想它应该对你有用,它会忽略情况。
即。"...(?i)(jpg|jpeg|gif|png|wpf|...
"
希望能有所帮助。
只需使用Regex.IsMatch
的重载,允许您指定选项:
return Regex.IsMatch(input, string.Format(@"b{0}b", Regex.Escape(match)), RegexOptions.IgnoreCase);
RegexOption。IgnoreCase应该是一个选项。
Regex.IsMatch(input, string.Format(@"b{0}b", Regex.Escape(match)), RegexOptions.IgnoreCase)