YouTube ID parser

Public

Get a YouTube URL and parse it to get the ID using only JavaScript. Found it on Stackoverflow at: http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-y...

</> CopyGet raw version
javascript
  1. function youTubeProcess(url) {
  2. if(url) {
  3. var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
  4. var match = url.match(regExp);
  5. if (match&&match[2].length==11){
  6. return match[2];
  7. }
  8. else{
  9. return false;
  10. }
  11. }
  12. else {
  13. return false;
  14. }
  15. }