一致した正規表現文字列の一部だけを置き換えるにはどうすればよいですか? のようないくつかの括弧内にあるいくつかの文字列を見つける必要があります< >
。この例では、23 文字を照合し、そのうち 3 文字だけを置き換える必要があります。
string input = "<tag abc=\"hello world\"> abc=\"whatever\"</tag>";
string output = Regex.Replace(result, ???, "def");
// wanted output: <tag def="hello world"> abc="whatever"</tag>
したがって、 を検索abc
する<tag abc="hello world">
か、検索<tag abc="hello world">
して置き換える必要がありますabc
。正規表現または C# はそれを許可しますか? また、問題を別の方法で解決したとしても、大きな文字列を一致させて、その一部だけを置き換えることは可能ですか?