"<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的值?

解决方案 »

  1.   

    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";
                }