I want to replace the text between the tags upcase to its uppercase version. Is there a way to do it by only using Regex.Replace method? (without using IndexOf)
Below is the code I was trying:
string texto = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
Console.WriteLine(Regex.Replace(texto, "<upcase>(.*)</upcase>", "$1".ToUpper()));
The expected result is:
We are living in YELLOW SUBMARINE. We don't have ANYTHING else.
but I get:
We are living in yellow submarine. We don't have anything else.
"<upcase>(.*?)</upcase>"ToUpperwill apply to the "$1" and have no effect.Regex.Replacethat takes a delegate that allows you to manipulate the matches. Just check out Avinash's answer.