views:

31

answers:

1

How can i extract src attribut of embed tag with regeex?

in this exemple(youtube video):

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Ora35AzLxt0?fs=1&amp;amp;hl=fr_FR"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Ora35AzLxt0?fs=1&amp;amp;hl=fr_FR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

i'am only able to extract the complete tag with this regex: \<embed[>](.?)</embed>

result: <embed src="http://www.youtube.com/v/Ora35AzLxt0?fs=1&amp;amp;hl=fr_FR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>

is it possible to get only the value of attribut src?

Thanks!

+1  A: 

Please do not use regexp where it is unnecessary...

var htmlcode = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Ora35AzLxt0?fs=1&amp;amp;hl=fr_FR"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Ora35AzLxt0?fs=1&amp;amp;hl=fr_FR" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';

div = document.createElement('div');
div.innerHTML = htmlcode ;
var yourSrc = div.getElementsByTagName('embed')[0].src;
dev-null-dweller
yeahhh, thank a lot!
Christian