I haven't used regular expressions at all, so I'm having difficulty troubleshooting.
(我根本没有使用过正则表达式,因此我很难进行故障排除。)
I want the regex to match only when the contained string is all numbers; (我希望正则表达式仅在包含的字符串为全数字时才匹配;)
but with the two examples below it is matching a string that contains all numbers plus an equals sign like "1234=4321". (但是在下面的两个示例中,它匹配包含所有数字和等号(例如“ 1234 = 4321”)的字符串。)
I'm sure there's a way to change this behavior, but as I said, I've never really done much with regular expressions. (我敢肯定有一种方法可以改变这种行为,但是正如我所说,我从未真正对正则表达式做过很多事情。)
string compare = "1234=4321";
Regex regex = new Regex(@"[d]");
if (regex.IsMatch(compare))
{
//true
}
regex = new Regex("[0-9]");
if (regex.IsMatch(compare))
{
//true
}
In case it matters, I'm using C# and .NET2.0.
(万一重要,我使用的是C#和.NET2.0。)
ask by Timothy Carter translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…