110,983
社区成员
发帖
与我相关
我的任务
分享
Regex regCss = new Regex(@"<link\b[^<>]*?\bhref[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<cssUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
<link href="xxx.ico" rel="shortcut icon" />
<link href="templates/dede/skins/default/dedecms.css" rel="stylesheet" type="text/css" />
<link href="templates/dede/skins/default/asd2cms.css" rel="stylesheet" type="text/css" />
<link href="templates/dede/skins/default/de3213cms.css" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss+xml" title="xxxxxx" href="/rss.php?rssid=47" />
favicon.ico
templates/dede/skins/default/dedecms.css
templates/dede/skins/default/asd2cms.css
templates/dede/skins/default/de3213cms.css
/rss.php?rssid=47
void Main()
{
string html=@"<link href=""xxx.ico"" rel=""shortcut icon"" />
<link href=""templates/dede/skins/default/dedecms.css"" rel=""stylesheet"" type=""text/css"" />
<link href=""templates/dede/skins/default/asd2cms.css"" rel=""stylesheet"" type=""text/css"" />
<link href=""templates/dede/skins/default/de3213cms.css"" rel=""stylesheet"" type=""text/css"" />
<link rel=""alternate"" type=""application/rss+xml"" title=""xxxxxx"" href=""/rss.php?rssid=47"" />";
foreach(Match m in Regex.Matches(html,@"(?is)<link[^>]+?href=(['""]?)[^'""]+\1[^>]+type=\1text/css\1[^>]*/>"))
{
Console.WriteLine(m.Value);
}
}
/*
<link href="templates/dede/skins/default/dedecms.css" rel="stylesheet" type="text/css" />
<link href="templates/dede/skins/default/asd2cms.css" rel="stylesheet" type="text/css" />
<link href="templates/dede/skins/default/de3213cms.css" rel="stylesheet" type="text/css" />
*/
Regex regCss = new Regex(@"(?i)<link\b[^<>]*?\bhref\s*=\s*[""']?(?<cssUrl>[^\s""'>]*?\.css)[\s'"">]");