I have the following html content
<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>
Here i have two <a>
tags. I need the value of href of the <a>
node where the attribute 'src' is that of the second <a>
node i.e \" http://confluence:8080/download/thumbnails/8618175/attachment.jpg的href值\“我有一个变量说字符串x包含此值,我需要获取{{的href 1}}节点基于此值。
现在我正在使用“href \ s * = \ s *(?:\”(?&lt; 1&gt; [^ \“] *)\”|(?&lt; 1&gt; \ S +))“但是它给了我所有节点的href值。
答案 0 :(得分:0)
我完全赞同Wiktor S.即HTML Agility Pack是一个比Regex更强大的解决方案。但是如果你必须使用正则表达式,试试这个......
<a[^>]*href\s*=(?<HRef>[^>]+)>