2014-01-28 78 views
0

如何用C#中的正則表達式(正則表達式)替換單詞?如何用正則表達式替換單詞?

實施例:

string _test = "Test2 Test Test() Function(Test)"; 
_test = Regex.Replace(_test, regexVariable, "Boat"); 

將導致_test具有值"Test2 Boat Boat() Function(Boat)"

回答

2

word boundary character見文檔,\b

Regex.Replace("Test2 Test Test() Function(Test)", @"\bTest\b", "Boat") 

輸出:

Test2 Boat Boat() Function(Boat)