0

Possible Duplicate:
jQuery Youtube URL Validation with regex
YouTube url id Regex

http://www.youtube.com/watch?v=SCS7SIeF30E

http://www.youtube.com/watch?v=SCS7SIeF30E&feature=relmfu

http://www.youtube.com/v/SCS7SIeF30E

How can I grab videoid SCS7SIeF30E from the above possible URL using javascript regular expression.

I know it has been asked many time but I am searching for Regex which cover v/ also in url all regex only covers v= type url.

Community
  • 1
  • 1
SOF User
  • 7,590
  • 22
  • 75
  • 121
  • 2
    This has been asked many times before. See the "Related" column or Stack Overflow's search – Pekka Dec 26 '11 at 15:05
  • yep I know its posted but that regex work for only v= while I have posted for regex which can be work with v/ like this – SOF User Dec 26 '11 at 15:10
  • 1
    Then look at more than just one duplicate. [YouTube url id Regex](http://stackoverflow.com/q/8388223) – Pekka Dec 26 '11 at 15:15
  • I provide a JavaScript regex solution to your question in [my popular answer](http://stackoverflow.com/a/5831191/433790) to a very similar question: [php regex - find all youtube video ids in string](http://stackoverflow.com/q/5830387/433790) – ridgerunner Dec 26 '11 at 16:31

1 Answers1

2
var myString = "http://www.youtube.com/v/SCS7SIeF30E";

var newString = myString.replace(/http:\/\/www.youtube.com\/v\//, "");

alert(newString);
Rob W
  • 341,306
  • 83
  • 791
  • 678
rleir
  • 791
  • 1
  • 7
  • 19
  • Syntax errors: `/` has to be escaped. Error in RegEx: `.` does not match a literal dot. Also, this method is very inflexible, and will not work for `watch`-URLs. – Rob W Dec 26 '11 at 15:22
  • Yes, sorry about the '/'s. I had it working in FF scratchpad, but cut and paste changed it. HTH – rleir Dec 28 '11 at 13:21
  • I see the cause. Your code has to be formatted, by prefixing 4 spaces. – Rob W Dec 28 '11 at 13:29