function isOembed(url) {
var pattern = /http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*|.*\.youtube\.com\/.*#.*\/.*|m\.youtube\.com\/watch.*|m\.youtube\.com\/index.*|.*\.youtube\.com\/profile.*/;
return pattern.test(url);
}
alert(isOembed('http://www.youtube.com/watch?v=9W8Ie4MyRX0&feature=related'));
Why does the following regex produce nothing? I've tried it in jsFiddle.
The lint says:
Error:
Problem at line 2 character 223: Unescaped '/'.
v开发者_Python百科ar pattern =/http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|y...
Implied global: alert 6
jonnnnnnnnnie was right, just add a ) at end of the regex, like this: http://jsbin.com/ufufed/2/
var pattern = /http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*|.*\.youtube\.com\/.*#.*\/.*|m\.youtube\.com\/watch.*|m\.youtube\.com\/index.*|.*\.youtube\.com\/profile.*)/;
精彩评论