string FaPiaoUrl = ""; string FaPiaoImageUrl = ""; string HTMLSTR = NetTools.GetResponse(Dr["InvoiceUrl"].ToString()); string pattern = @"(?=http).*(?<=\.pdf|.png)"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(HTMLSTR); foreach (System.Text.RegularExpressions.Match match in matches) { if (Path.GetExtension(match.Value).ToLower() == ".png") { FaPiaoImageUrl = match.Value; } else if (Path.GetExtension(match.Value).ToLower() == ".pdf") { FaPiaoUrl = match.Value; } }
标签:网页,string,C#,正则,获取,地址 From: https://www.cnblogs.com/work-code/p/17972333