views:

32

answers:

2
function checkVideoUrl(url){
    var regex= [],urlmatch= false;

    regex[0] = /http:\/\/www.56.com\/\S+\/([^\/]+).html/i;

    for(i=0;i<regex.length;i++){
      urlmatch =regex[i].test(url); 
      if(urlmatch == true) break;
    }
    return urlmatch;
}
alert(checkVideoUrl('http://www.56.com/w68/album-aid-8529817.html'));//true
alert(checkVideoUrl('http://www.56.com/u96/v_NTQ5MTM1ODE.html'));//true

how can i match http://www.56.com/u96/v_NTQ5MTM1ODE.html only.

thanks a lot.

A: 

Don't bother with regular expressions when they aren't needed...

function checkVideoUrl(url)
{
    return url == "http://www.56.com/u96/v_NTQ5MTM1ODE.html";
}
Kristoffer S Hansen
And here I'd done that (but with the "l" at the end) as a humorous comment...
T.J. Crowder
I have seen the error of my ways and will try to correct them
Kristoffer S Hansen
A: 

Assuming v_ indicates that it's a video URL:

/http:\/\/www.56.com\/\S+\/v_([^\/]+).html/i;

This will also capture the NTQ5MTM1ODE part, which is probably the video ID.

Andy E