If all you want to do is replace Old ending with New ending , why don't you just use the good old string.Replace ? It will be simpler and faster than using regex
String s = "Beginning of story. Keep this sentence. Old ending.\n"; s.Replace("Old ending", "New ending");
Update: To replace Old ending , where it is preceded by Begining of story... , use this regular expression (?<=Beginning of story.*?)Old ending , play with it if you have small changes, but this should lead you there
Regex.Replace(s, @"(?<=Beginning of story.*?)Old ending", "New ending");
It basically says, find and replace “Old End” with “New Finale”, but only if it starts with “Begin Blah Blah Blah History”
Jason
source share