如何在不匹配给定文本前缀的情况下替换文本值?
例如:
test hello world... I know hello world, this seems hello world..
那么我们的替换值为“HI”
文本将是..
test hello world... I know HI, this seems HI..
如何在不匹配给定文本前缀的情况下替换文本值?
例如:
test hello world... I know hello world, this seems hello world..
那么我们的替换值为“HI”
文本将是..
test hello world... I know HI, this seems HI..
(?<!test\s)\bhello world\b
这假设您对直接进行的测试感兴趣。
要有点聪明并避免使用正则表达式,您可能会做这样的事情
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