取得HTML中全部圖片的 URL 正則表達式
- public static string[] GetHtmlImageUrlList(string sHtmlText)
- {
-
- Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
-
-
- MatchCollection matches = regImg.Matches(sHtmlText);
- int i = 0;
- string[] sUrlList = new string[matches.Count];
-
-
- foreach (Match match in matches)
- sUrlList[i++] = match.Groups["imgUrl"].Value;
- return sUrlList;
- }
歡迎關注本站公眾號,獲取更多信息