Youtube without Flash Auto

By YoutubeWithoutFlash Last update Jan 30, 2011 — Installed 97,156 times.

regexp

in
Subscribe to regexp 1 post, 1 voice

waldir Scriptwright
FirefoxX11

While I was trying to make this work with html5's video tag (see relevant discussion) I noticed that there were some regexp instructions that could be simplified a little.

Here's the original:

vidurls = urlmap.split(/\%2C[0-9]+\%7C/);
vidformats = urlmap.match(/[0-9]+(?=\%7C)/g);
for (var i=0; i<vidurls.length; i++)
{
    vidurls[i] = vidurls[i].match(/(http.*)/)[0];
    vidurls[i] = unescape(vidurls[i]);
}

And here's what I think is a somewhat improved version:

urlmap = unescape(urlmap);
vidurls = urlmap.split(/,?\d+\|/);
vidurls.shift();
vidformats = urlmap.match(/\d+(?=\|)/g);

Note: the shift() removes the first element of the array, which is an empty string
(since the splitting separator matches the beginning of the string)

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel