How to Regex search/replace only first occurrence in a string in .NET?

后端 未结 4 996
傲寒
傲寒 2020-11-29 10:46

It seems the .NET Regex.Replace method automatically replaces all matching occurrences. I could provide a MatchEvaluator delegate that returns the matched string after the

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 11:31

    From MSDN:

    Replace(String, String, Int32)   
    

    Within a specified input string, replaces a specified maximum number of strings that match a regular expression pattern with a specified replacement string.

    Isn't this what you want?

提交回复
热议问题