How To Modify A Regular Expression To Parse A Parameter From A YouTube URL
I've got this regular expression: /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; It will parse the video id from a YouTube URL such as http://
Solution 1:
Capture YouTube video ID (and time seek parameter t
if exists)
RegExp:
^(?:https?\:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v\=))([\w-]{10,12})(?:[\&\?\#].*?)*?(?:[\&\?\#]t=([\dhm]+s))?$
Demo here: http://fiddle.re/w1nn6
PS: you'll note I improved your original RegEx to validate the YouTube link safely
Post a Comment for "How To Modify A Regular Expression To Parse A Parameter From A YouTube URL"