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

后端 未结 4 997
傲寒
傲寒 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:48

    Just to answer the original question... The following regex matches only the first instance of the word foo:

    (?

    This regex uses the negative lookbehind (?

提交回复
热议问题