Wednesday 15 July 2015

c# - Regex replace all occurrences -


I need to change a string where it follows a specific string and some different data to keep me started and mid The end space is needed when I try the code given below, it only changes the last chance I have tried to switch to a non-greedy match but then it did not get it. In the middle there may be new lines, spaces, letters and numbers.

  string s = "beginning of the story: Keep this sentence. Old termination. \ N"; S + = s; S + = s; S1 = Regex.Replace (s, @ "Story's Beginning. ([\ S \ S] *) Old End.", "The Story Begins" + @ "$ 1" + "New End.", Reggaeups. RegexOptions.IgnoreCase); The result is: Let the beginning of the story be the beginning of the story of the old closing story. Put this sentence in the beginning of the old closing story. Keep this sentence the beginning of the old closing story. Keep this sentence New termination   

I How do I change every opportunity of "ending"?

I think that Kendall is a band with related links, eg.

  s1 = Regex.Replace (s, @ "The beginning of the story. ([\ S \ S] *?) Older closing.", "The beginning of the story" + @ "$ 1" + "New End.", Reggae Option Multiline | Reggaeops.Eggner Case);   

Should do the trick.

EDIT:

You should be able to change the pattern in your capture area: . * where . will match any character except the new characters.

No comments:

Post a Comment