Reputation: 1640
How can I replace text value without matching given prefix of text??
For Example:
test hello world... I know hello world, this seems hello world..
then our replace value is "HI"
the text will be..
test hello world... I know HI, this seems HI..
Upvotes: 0
Views: 693
Reputation: 13579
to be somewhat clever and to avoid regular expression you might do something like this
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
Upvotes: 0
Reputation: 5016
(?<!test\s)\bhello world\b
This assumes that you're interested in test when it proceeds directly.
Upvotes: 1