Reputation: 8963
I'm coding an app in Phonegap and I'm trying to extract the video-ID from an XML file.
This is part of the XML containing the iFrame
<lees-verder>
<![CDATA[
<p><iframe width="720" height="396" src="http://www.youtube.com/embed/53_qvMQfvOE?rel=0" frameborder="0" allowfullscreen></iframe></p>
]]>
</lees-verder>
This is the Jquery I use to parse "lees-verder".
var long = myObj.find('lees-verder').text();
My question is: How do I write the Jquery action more specific, so it splits the element and gives me the 11-character-long video-ID? I started with this, but I don't know if I'm going the right direction
var ytube = long.substring(long.
Thanks!
Upvotes: 0
Views: 205
Reputation: 168957
Use a regular expression once you have the text in the variable long
:
var ytube = null;
var match = /embed\/([A-Za-z0-9_]+)/.exec(long);
if(match) ytube = match[1]; // Found it!
Upvotes: 1