Skip to content

Regex to extract the youtube id from given youtube url

License

Notifications You must be signed in to change notification settings

Quehnie/youtube-id-regex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GET YOUTUBE ID FROM URL

Regex to extract the youtube id from given url.

Install

Install with npm

$ npm install youtube-id-regex

Usage

var youtubeIdRegex = require('youtube-id-regex');
youtubeIdRegex().test('yourString') // Returns true or false.
youtubeIdRegex().exec('yourString')[1]; // Returns the youtube id.

Possible strings containing youtube id

Supports both domains

Urls with youtube.com but also youtube-nocookie.com are supported.

Urls with different queries

// Results as true.
youtubeIdRegex().test('youtube.com/watch?v=z9dIAG2gpwc');
youtubeIdRegex().test('youtube.com/watch?feature=related&v=z9dIAG2gpwc');
youtubeIdRegex().test('youtube.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('www.youtube.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('youtube-nocookie.com/watch?feature=related&v=z9dIAG2gpwc');
youtubeIdRegex().test('youtube-nocookie.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('www.youtube-nocookie.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('https://www.youtube-nocookie.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('http://www.youtube-nocookie.com/watch?v=z9dIAG2gpwc&feature=related');
youtubeIdRegex().test('http://www.youtube.com/watch?v=z9dIAG2gpwc');
youtubeIdRegex().test('http://www.youtube.com/watch?feature=related&v=z9dIAG2gpwc');

Sentence contains youtube url

// Results as true.
youtubeIdRegex().test('Just some text with this https://www.youtube.com/watch?v=z9dIAG2gpwc youtube video link in it.');

Author

Quehnie

About

Regex to extract the youtube id from given youtube url

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published