【问题标题】:Extract image URL in a string (RSS with syndicationfeed)提取字符串中的图像 URL(RSS 与 syndicationfeed)
【发布时间】:2012-03-01 13:45:28
【问题描述】:

我有这个:

<img src="http://MyUrl.JPG.jpg" width="180" ...

我需要这个:

http://MyUrl.JPG.jpg

谢谢

【问题讨论】:

标签: c# string windows-phone-7 rss


【解决方案1】:

如果这真的是全部你有你可能摆脱正则表达式,如

src="([^"]+)

但是,您不能也不应该尝试使用正则表达式解析 HTML。 Using regular expressions to parse HTML: why not?

请改用 Html Agility Pack 之类的 HTML 解析器。不过,我不知道它是否适用于 WP7。

【讨论】:

【解决方案2】:

使用正则表达式的完整解决方案:

string source ="<img src=\"http://MyUrl.JPG.jpg\"";
var reg = new Regex("src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|bmp|gif|png))(?:\"|\')?");
var match=reg.Match(source);
if(match.Success)
{
  var encod = match.Groups["imgSrc"].Value;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多