Match and replace

后端 未结 5 2075
有刺的猬
有刺的猬 2020-12-08 14:03

I have a long string and within that string I have the following text:

\"formatter\": \"SomeInformationHere\"

I need to fi

5条回答
  •  时光取名叫无心
    2020-12-08 14:57

    Use this:

    string longString = @"""formatter"": ""SomeInformationHere""";
    string pattern = "(\"formatter\": )([\"])(.*)([\"])";
    string result = Regex.Replace(longString, pattern, "$1$3");
    

    This replaces all found matches with the second and the fourth sub group of the match. The complete match is the first sub group ($0) and all parts in parenthesis create a new sub group.

提交回复
热议问题