问个正则表达式的问题

caixrz 2008-09-16 09:04:32
"<div id=\"fontstyle\" style=\"font-size=11; font-family=隶书; color=Red;\">sadf;lkjsa;dfk l k l k l 策划四||face:102.gif||</div>"


如何用正则表达式得到 font-size,font-family和color的值?
...全文
59 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
家鸣 2008-09-16
  • 打赏
  • 举报
回复
string result = "";
string src = "<div id=\"fontstyle\" style=\"font-size=11; font-family=隶书; color=Red;\">sadf;lkjsa;dfk l k l k l 策划四||face:102.gif|| </div>";
MatchCollection mc2 = Regex.Matches(src, @"<div.+style=[""']font\-size=(?<fontSize>[^;]+);\s*font\-family=(?<fontFamily>[^;]+);\s*color=(?<color>[^;]+)", RegexOptions.IgnoreCase);
foreach (Match m in mc2)
{
result += m.Groups["fontSize"].Value + "\r\n" + m.Groups["fontFamily"].Value + "\r\n" + m.Groups["color"].Value + "\r\n";
}
january03 2008-09-16
  • 打赏
  • 举报
回复
帮顶。UP
LovingAlison 2008-09-16
  • 打赏
  • 举报
回复
不会 帮你顶

111,092

社区成员

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

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

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