Regex word boundary expressions

前端 未结 4 421
时光说笑
时光说笑 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:38

    As Gopi said, but (theoretically) catching only (three) not two(three):

    string input = "one two(three) (three) four five";
    
    string output = input.Replace(" (three) ", " (four) ");
    

    When I test that, I get: "one two(three) (four) four five" Just remember that white-space is a string character, too, so it can also be replaced. If I did this:

    //use same input
    string output = input.Replace(" ", ";");
    

    I'd get one;two(three);(three);four;five"

提交回复
热议问题