我已經得到了以下REG EXP正則表達式替換
(-[^\w+])|([\w+]-[\w+])
我想用它用空格來代替破折號
test -test should not be replaced
test - test should be replaced
test-test should be replaced
所以只有當測試 - 測試劃線不應被替換。
當前([\ w +] - [\ w +])正在取代周圍的短劃線。
var specialCharsExcept = new Regex(@"([\w+]-[\w+])", RegexOptions.IgnoreCase);
if (string.IsNullOrEmpty(term))
return "";
return specialCharsExcept.Replace(term, " ");
任何幫助?在此先感謝
PS:我正在使用C#。
更新
我想現在使用下列情況下,你REG進出口。
some - test "some test" - everything within the quotes the expression should not be applied
這可能嗎?
應該帶些什麼來替代? – 2010-01-21 11:16:28
你確定它是'[\ w +]'而不是'\ w +'嗎?前者匹配所有字母數字(和'_')以及加號。 – kennytm 2010-01-21 11:17:32
破折號應該用空格代替 – Chris 2010-01-21 11:20:38