如何在不匹配給定文本前綴的情況下替換文本值?正則表達式如果單詞與給定前綴不匹配,則替換髮現的所有匹配項
例如:
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..
是有點聰明,避免正則表達式,你可能會做這樣的事情
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
這個詞的時候「測試」是不是之前的「Hello World」你是什麼意思? –
所以你的意思是你想要用hi代替字符串中的hello世界 –
如果在找到hello世界之前進行了單詞測試,將不會有替換過程。但如果沒有找到,你好世界將被替換爲HI – lexeRoy