I have a situation where I have a string in which I have to replace a part that lies between special characters. I can do the same using substrings and length,but that is the dirty way. Is there any better way of doing this using regex?
e.g. of the string is
string str1 = "This is the <![CDATA[ SampleDataThatNeedsToBeReplaced ]]";
string repl = "Replacement Text";
I need a regex to get the output as
This is the Replacement Text
I did try a few regex like the following
result = Regex.Replace(str1, @"(?<=CDATA\[)(\w+?)(?=\]\])", repl);
I also tried
Regex x = new Regex("(\\[CDATA\\])(.*?)(\\[\\]\\]\\])");
string Result = str1.Replace(text, "$1" + repl + "$3");
did not get any results. Any help is appreciated.