[英]Regex Replace all found occurrences if the word not matches with the given prefix
如何在不匹配給定文本前綴的情況下替換文本值?
例如:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.