如何用正则表达式替换Html中的特殊编码(&,&absp;等)呢

114 2010-09-13 09:41:38
Henrich R. Greve; Donald&Palmer;*Jo-ellen Pozner


这是一段HTML源代码,我用“;”进行split到数组中,因为有类似“ ”这样的编码干扰,导致split不准确,如何得到这样的结果:
1. Henrich R. Greve
2.  Donald&Palmer
3. *Jo-ellen Pozner

请高手出招!
...全文
152 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2010-09-13
  • 打赏
  • 举报
回复
or...

string test = "Henrich R. Greve; Donald&Palmer;*Jo-ellen Pozner";
Regex reg = new Regex(@"(?<!&[^;]*);");
string[] arr = reg.Split(test);
foreach(string s in arr)
{
richTextBox2.Text += s + "\n";
}
-过客- 2010-09-13
  • 打赏
  • 举报
回复
try...

string test = "Henrich R. Greve; Donald&Palmer;*Jo-ellen Pozner";
Regex reg = new Regex(@"((?:&[^;]*;|[^;])+);?");
MatchCollection mc = reg.Matches(test);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧