日期:2014-05-18 浏览次数:20739 次
string temp = @"比如说我有个网页内容如下 <link type='text/css' rel='stylesheet' href='a.css' /><link type='text/css' rel='stylesheet' href='b.css' /><div><input/></div> "; string[] arr= Regex.Matches(temp, @"(?i)<link[^>]*?href=(['""])([^'""]*?)\1[^>]*?>").Cast<Match>().Select(a => a.Groups[2].Value).ToArray(); /* * a.css * b.css */
------解决方案--------------------
string str = "<link type='text/css' rel='stylesheet' href='a.css' /><link type='text/css' rel='stylesheet' href='b.css' /><div><input/></div>";
Regex.Matches(str, @"<link[\s\S]*?href=['""]([^'""]+)['""][^/]+/>").Cast<Match>().ToList().ForEach(t => Console.WriteLine(t.Groups[1].Value));
------解决方案--------------------
(?i)<link\b[^>]*?href=(['"]?)([^"']*?)\1[^>]*?/>
取Groups[2].Value