我在使用正則表達式時遇到問題。正則表達式與預期的不匹配
我有以下代碼:
string d = "moveUp(),;moveDown();";
string[] s = Regex.Split(d, ",");
foreach (string line in s)
{
string line1 = line.Replace("\n", null);
line1 = line1.Replace("\r", null);
string pattern = @"^moveUp();$";
bool a1 = Regex.IsMatch(line1, pattern);
if (!a1)
{
warning.Text = "error";
return;
}
}
爲什麼是a1
false
這裏的價值?
一個普通的舊字符串比較比正則表達式要簡單得多:'!line1.Equals(「moveUp();」)'你顯然不需要通配符,沒有組,沒有捕獲......爲什麼*你使用正則表達式? – stakx