1
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 '/'.
var pattern =/http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|y...

Implied global: alert 6
1
  • 17
    You can post that comment as an answer to your own question. G'wan, try it. You know you wanna. Commented Aug 9, 2011 at 17:57

1 Answer 1

1

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.*)/;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.