我已经得到了以下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