我根本没有使用正则表达式,所以我很难排除故障.我希望正则表达式只在包含的字符串是所有数字时匹配; 但是下面的两个例子是匹配一个包含所有数字的字符串加上一个等号"1234 = 4321".我确信有一种方法可以改变这种行为,但正如我所说,我从未真正对正则表达式做过多少工作.
string compare = "1234=4321";
Regex regex = new Regex(@"[\d]");
if (regex.IsMatch(compare))
{
//true
}
regex = new Regex("[0-9]");
if (regex.IsMatch(compare))
{
//true
}
Run Code Online (Sandbox Code Playgroud)
如果重要,我正在使用C#和.NET2.0.