如何在不匹配给定文本前缀的情况下替换文本值?
例如:
test hello world... I know hello world, this seems hello world..
那么我们的替换值是"HI"
文本将是..
test hello world... I know HI, this seems HI..
(?<!tests)bhello worldb
这假设你对直接进行的测试感兴趣。
为了有点聪明并避免正则表达式,您可以执行以下操作
string v = s.Replace("hello world", "HI"); //replace hello world in all occurrences with HI
string newstring = v.Replace("test HI", "hello world"); //place hello world where hi is after test