日期:2014-05-18 浏览次数:20836 次
abc<sup>1,2</sup>,defdfe<sup>3,4</sup>,ghijdfd,fdfdk
abc<sup>1,2</sup>;defdfe<sup>3,4</sup>;ghijdfd;fdfdk
Regex reg = new Regex(@"(?i)(?<=^|</sup>).+?(?=<sup>|$)"); string result = reg.Replace(yourStr, delegate(Match m) { return m.Value.Replace(",", ";"); });
------解决方案--------------------
var testSource = "abc,<sup>1,2,</sup>,defdfe<sup>3,4</sup>,ghijdfd,fdfdk<sup><span>,ss</span></sup>456464,"; var pattern = @",(?!(?:(?!</?sup\b).)*</sup\s*>)"; var resultStr = Regex.Replace(testSource,pattern,";",RegexOptions.IgnoreCase); Console.WriteLine(resultStr);