C#怎么替换两个有规律的字符串啊?
比如:
1X23Y4
1A23B4
……
有什么办把1和2之间的字符串替换成3和4之间字符串啊?
c#
------解决方案--------------------string str1 = "1";
string str2 = "2";
string str3 = "3";
string str4 = "4";
string str = "1X23Y4";
string pattern = string.Format(@"(?<={0})(((?!{1}).)*)(?={1}{2}((?!{3}).)*{3})", str1, str2, str3, str4);
str = Regex.Replace(str, pattern, "$3");
------解决方案--------------------
改下正则
string pattern = string.Format(@"(?<={0})(((?!{1}).)*)(?={1}{2}(((?!{3}).)*){3})", str1, str2, str3, str4);