FindTxt="<h1>中国</h1>1月"
FindTxt = FindTxt.Replace("1", "<font color=red>" + "1" + "</font>");
我只想把1月的1变红,html标签内的不变,求指点
FindTxt = FindTxt.Replace("1", "<font color=red>" + "1" + "</font>");
我只想把1月的1变红,html标签内的不变,求指点
string sourceString = @"<h1>中国</h1>1月";
string pattern = @"(<h1>[^>]*>)(?<month>\d{0,2})([\u4e00-\u9fa5])";
string result = System.Text.RegularExpressions.Regex.Replace(sourceString,pattern,@"$1<font colore=""red"">${month}</font>$2");
//////////////////////////////////////////////
MSN:[email protected]请给我一个与您交流的机会!
{ return m.ToString().Replace("1", "<font color=red>" + "1" + "</font>");
}
FindTxt = Regex.Replace(FindTxt,@"(<h1>中国</h1>)(\S+?)(月)","$1<font color=red>$2</font>$3");我要分
string sourceString = @"<h1>中国</h1>1月";
string pattern = @"(<h1>[^>]*>)(?<month>[^<]*)";
string result = System.Text.RegularExpressions.Regex.Replace(sourceString,pattern,@"$1<font colore=""red"">${month}</font>");
//////////////////////////////////////////////
MSN:[email protected]请给我一个与您交流的机会!
string strRegex = @"(<h1>.*</h1>)(\d{1,2})";
string result = Regex.Replace(FindTxt, strRegex, "$1<font color=red>$2</font>");
Console.WriteLine("{0}", result);输出结果:<h1>中国</h1><font color=red>1</font>月
string findTxt="<h1>中国</h1>1月";
string strRegex = @"(<h1>中国</h1>)(\d{1,2})(月)"; //如果"中国"不是必有的则用 .*
string result = Regex.Replace(findTxt, strRegex, "$1<font color=red>$2</font>$3");
Console.WriteLine("{0}", result);输出结果:<h1>中国</h1><font color=red>1</font>月