我正在尝试使用 Regex 类在我的 c# 程序上实现两个 oracle 通配符“%”和“_”。问题是当我有通配符“_”时,因为我只需要接受一个字符,但每次我有至少一个字符时它都会返回 true。你能帮我么?
这是我的代码:
string filter, string1;
string wildcard1 = "[" + "\\d | " + "\\n | " + "\\s |" + "\\w]+";
string wildcard2 = "[" + "\\d | " + "\\n |" + "\\s | " + "\\w]{1}";
filter = Regex.Replace(filter, "%", wildcard1);
filter = Regex.Replace(filter, "_", wildcard2);
Regex regex1 = new Regex(filter, RegexOptions.IgnoreCase);
MatchCollection a = regex1.Matches(string1);
if (regex1.IsMatch(string1))
{
return true;
}