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="" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" flashvars="">';

// 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