gpt4 book ai didi

c# - 使用正则表达式的图像标签的 src

转载 作者:太空宇宙 更新时间:2023-11-03 18:31:24 25 4
gpt4 key购买 nike

我需要通过对以下字符串使用 regex 来找到第一个 img 标签的 src。怎么做?

><div dir="ltr" style="text-align: left;" trbidi="on"><div class="MsoNormal"
style="background: white; line-height: 15.0pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-outline-level: 2; vertical-align: baseline;"><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-c-ugY7XUnYo/UoJtj0dzvKI/AAAAAAAAACA/qWtvYnP9wfc/s1600/Screen+shot+2013-11-12+at+10.03.25+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="257" src="http://1.bp.blogspot.com/-c-ugY7XUnYo/UoJtj0dzvKI/AAAAAAAAACA/qWtvYnP9wfc/s320/Screen+shot+2013-11-12+at+10.03.25+AM.png" width="320" /></a></div><h4><span style="background-color: transparent;">With over 150,000 pet care professionals in the United States, your ability to differentiate your business is critical to long-term sustainable growth.  By focusing on the customer experience you can gain the loyalty of prospective pet parents and continue to thrive with your current pack.</span><span style="background-color: transparent;">  </span><span style="background-color: transparent;">Below are 5 ways to differentiate your pet business so you have a leg up on your local competitors.</span></h4></div><div class="MsoNormal"><div

最佳答案

Don't use Regex to parse html .使用真正的 html 解析器,如 HtmlAgilityPack

var html = WebUtility.HtmlDecode(yourtext);
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
var urls = doc.DocumentNode.SelectNodes("//img[@src]")
.Select(img => img.Attributes["src"].Value)
.ToList();

关于c# - 使用正则表达式的图像标签的 src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21721686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com