//Code
string value = "abcBdefsbeBtestbtest123B";//要处理的字符串
MatchCollection re = Regex.Matches(value, "b", RegexOptions.IgnoreCase);
//忽略大小写搜索字符串中的关键
for (int j = 0; j < re.Count; j++)//循环在匹配的子串前后插入html
{
//j×31为插入html标签使pain字符串增加的长度:
value = value.Insert((re[j].Index + "b".Length + j * 31), "</span>");//关键字后插入html标签
value = value.Insert((re[j].Index + j * 31), "<span style='color:red'>");//关键字前插入html标签
}