I am dilemma to decide which one to use, either to use Regex.Replace
or to use Regex.Matches
if you have to perform some logic on each matches to generate the replaced value.
Scenario: Reading a file (which can vary in the size) and then using the Regular expression to replace the matches. replaced value for each match is different and is generated by some logic.
Approach 1: Read the complete file, then find all the matches and then I do the foreach or for loop and replace them one by one.
Approach 2: Read the complete file, then uses the Regex.Replace method with the MatchEvaluator, where MatchEvaluator function performs the logic and returns the replaced value.
There is an article I would like to link here, which somehow gives me a feeling to not use, Regex.Replace. Link: https://blogs.msdn.microsoft.com/debuggingtoolbox/2008/04/02/comparing-regex-replace-string-replace-and-stringbuilder-replace-which-has-better-performance/