asp.net - get the href from an <A> tag in html -


hi have information being displayed html content on web page.

some of content can contain:

<p> <a href="/documents/content/files/my_mp3.mp3" target="_blank">     <img alt="" src="/pictures/content/images/play.jpg" style="width: 153px; height: 49px;"><br> </a> </p> 

what i'm looking take whole tag or "href" , store in variable...so can display somewhere else, (i.e. display in summary)

the image consistent need href.

i thinking like: if < > tag href contains ".mp3" "href"

the < > tag not contain id or runat. it's being entered using javascript html editor, there's no id or runat.

anyone know how done?

thanks

description

this expression will:

  • match anchor tags have href attribute ends in .mp3
  • will avoid difficult html edge cases

    <a\b(?=\s)(?=(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\shref="([^"]*.mp3)")(?:[^>=]|='[^']*'|="[^"]*"|=[^'"\s]*)*\s?>.*?<\/a>

enter image description here

example

live example: http://www.rubular.com/r/cmmfqdq0qx

sample text

note second anchor tag has pretty difficult edge cases trip expressions

<p> <a href="/documents/content/files/my_mp3.mp3" target="_blank">     <img alt="" src="/pictures/content/images/play.jpg" style="width: 153px; height: 49px;"><br> </a> <a onmouseover=' href="notthemp3yourelookingfor.mp3" ; if (6 > x) { funrotate(href) ; } ; ' href="/documents/content/files/difficulttofind.mp3" target="_blank">     <img alt="" src="/pictures/content/images/play.jpg" style="width: 153px; height: 49px;"><br> </a> </p> 

matches

group 0 have entire <a..>..</a> tag
group 1 have href value

[0][0] = <a href="/documents/content/files/my_mp3.mp3" target="_blank">     <img alt="" src="/pictures/content/images/play.jpg" style="width: 153px; height: 49px;"><br> </a> [0][1] = /documents/content/files/my_mp3.mp3   [1][0] = <a onmouseover=' href="notthemp3yourelookingfor.mp3" ; if (6 > x) { funrotate(href) ; } ; ' href="/documents/content/files/difficulttofind.mp3" target="_blank">     <img alt="" src="/pictures/content/images/play.jpg" style="width: 153px; height: 49px;"><br> </a> [1][1] = /documents/content/files/difficulttofind.mp3 

Comments