C#怎么用正则表达式提取链接和图片标签的属性

<a href="http://网页地址"> <img src="http://图片地址" width="240" title="图片标题" />怎么一次性提取上面 http://网页地址。http://图片地址 。图片标题?因为页面里有许多条上面这样的代码
2026-12-04 12:56:54
推荐回答(2个)
回答1:

StringCollection resultList = new StringCollection();
try {
    Regex regexObj = new Regex(@"\s*?");
    Match matchResult = regexObj.Match(subjectString);
    while (matchResult.Success) {
        resultList.Add(matchResult.Groups[1].Value);
        matchResult = matchResult.NextMatch();
    } 
} catch (ArgumentException ex) {
    // Syntax error in the regular expression
}

回答2:

是否一定要用正则?
用js或者jquery获取a标记或者img的属性也可以的