我目前拥有的正则表达式代码将寻找与case完全匹配的代码,因此我必须做出哪些更改才能忽略这种情况?
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)));
}
Run Code Online (Sandbox Code Playgroud)
小智 6
这应该工作:
public static bool ExactMatch(string input, string match)
{
return Regex.IsMatch(input, string.Format(@"\b{0}\b", Regex.Escape(match)), RegexOptions.IgnoreCase);
}
Run Code Online (Sandbox Code Playgroud)
该(?i)参数使正则表达式不区分大小写:
@"(?i)\b{0}\b"
Run Code Online (Sandbox Code Playgroud)
请注意,\b单词边界仅在搜索词以字母数字字符开头和结尾时起作用.