C# Regex获取特定的href值<;a>;节点

C# Regex获取特定的href值<;a>;节点,c#,regex,C#,Regex,我有以下html内容 <html><head> <title>Simple</title> </head> <body> <div id="Content" style="padding: 5px;"> <p><a href="http://confluence:8080/download/attachments/8618175/Text.txt?version=1&modifica

我有以下html内容

<html><head>
<title>Simple</title>


</head>
<body>
<div id="Content" style="padding: 5px;">
<p><a href="http://confluence:8080/download/attachments/8618175/Text.txt?version=1&modificationDate=1484637732181">Text.txt</a><br/>
<span class="image-wrap" style=""><img src="http://confluence:8080/download/attachments/8618175/add-button-blue-hi.png?version=1&modificationDate=1484562338796" style="border: 1px solid black" /></span><br/>
<span class="image-wrap" style=""><a class="confluence-thumbnail-link 300x200" href='http://confluence:8080/download/attachments/8618175/attachment.jpg'><img src="http://confluence:8080/download/thumbnails/8618175/attachment.jpg" style="border: 1px solid black" /></a></span></p>
</div>
</body></html>

简单的


这里我有两个
\“我有一个变量,比如字符串x,它包含这个值,我需要根据这个值获取
节点的href


现在我使用的是“href\s*=\s*(?:\”(?[^\“]*)\“|”(?\s+)”),但它给出了所有节点的href值。

我完全同意Wiktor的说法。也就是说,HTML Agility Pack是一个比正则表达式更健壮的解决方案。但是如果你必须使用正则表达式,试试这个

<a[^>]*href\s*=(?<HRef>[^>]+)>

这确实是一个很好的案例。使用XPath获取所有
a
标记的
src
值等于您的值,然后只获取它们的href值。另外: