Skip to main content

Needed a regular expression that would grab the "title" flash variable from YouTube iFrame API, ignoring the rest of variables. Here it is in JavaScript.

var subject = '<embed width="100%" height="100%" id="video-player-flash" tabindex="0" type="application/x-shockwave-flash" src="http://s.ytimg.com/yt/swfbin/watch_as3-vfl7F46ir.swf" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" flashvars="origin=http%3A%2F%2Fjonlabelle.com&el=embedded&fexp=907605%2C913415%2C911644%2C922401%2C920704%2C912806%2C924412%2C913558%2C912706&is_html5_mobile_device=false&allow_ratings=1&allow_embed=1&sendtmp=1&hl=en_US&cr=US&eurl=http%3A%2F%2Fjonlabelle.com%2Fgp%2F&iurl=http%3A%2F%2Fi1.ytimg.com%2Fvi%2Fh1g7JKvqQWI%2Fhqdefault.jpg&view_count=742&title=Introduction%20to%20Trigonometry&avg_rating=5&video_id=h1g7JKvqQWI&length_seconds=149&iurlmaxres=http%3A%2F%2Fi1.ytimg.com%2Fvi%2Fh1g7JKvqQWI%2Fmaxresdefault.jpg&enablejsapi=1&sk=VROzgSSQwdFfKXzGr1hUpnxVM6a-gs3gC&rel=1&playlist_module=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswfbin%2Fplaylist_module-vflE2WeSg.swf&iurlsd=http%3A%2F%2Fi1.ytimg.com%2Fvi%2Fh1g7JKvqQWI%2Fsddefault.jpg&jsapicallback=ytPlayerOnYouTubePlayerReady&playerapiid=player1&framer=http%3A%2F%2Fjonlabelle.com%2Fgp%2F">';

// capture everything between "title=" and "&"
var rvideoTitle = /title=(.*?)(&)/i;
var match = rvideoTitle.exec(subject);
var title = '';

if (match != null) {
  title = match[1]; // "Introduction%20to%20Trigonometry"
}

console.log(decodeURI(title)); // Introduction to Trigonometry