Regex word boundary expressions

前端 未结 4 414
时光说笑
时光说笑 2020-11-28 11:44

Say for example I have the following string \"one two(three) (three) four five\" and I want to replace \"(three)\" with \"(four)\" but

4条回答
  •  难免孤独
    2020-11-28 12:23

    Here a simple code you may be interested in:

        string pattern = @"\b" + find + @"\b";
        Regex.Replace(stringToSearch, pattern, replace, RegexOptions.IgnoreCase);
    

    Source code: snip2code - C#: Replace an exact word in a sentence

提交回复
热议问题