How can I replace only a part of a matched regex string ? I need to find some strings that are inside of some brackets like < >
. In this example I need to match 23 characters and replace only 3 of them:
string input = "<tag abc=\"hello world\"> abc=\"whatever\"</tag>";
string output = Regex.Replace(result, ???, "def");
// wanted output: <tag def="hello world"> abc="whatever"</tag>
So I either need to find abc
in <tag abc="hello world">
or find <tag abc="hello world">
and replace just abc
. Do regular expressions or C# allow that ? And even if I solve the problem differently is it possible to match a big string but replace only a little part of it ?