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
Just to answer the original question... The following regex matches only the first instance of the word foo:
(?
This regex uses the negative lookbehind (?