.net - Trouble with matching domain at the front and getting video id -


i trying modify following regex enforce domain either youtube or youtu.be. original regex meant provide in 2nd group id of video watching.
e.g. lvighymwrgs

my current test list

http://www.youtube.com/watch?v=lvighymwrgs&feature=feedrec_grec_index http://www.youtube.com/v/lvighymwrgs?fs=1&hl=en_us&rel=0 http://www.youtube.com/watch?v=lvighymwrgs#t=0m10s http://www.youtube.com/embed/lvighymwrgs?rel=0 http://www.youtube.com/watch?v=lvighymwrgs http://youtu.be/lvighymwrgs http://www.example.com/media/embed/83295164 

first regex

(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*) 

enter image description here

the problem example.com matches!

so tried modifying regex following ensure either youtube or youtu.be in url:

((youtu.be\/)|(youtube.com\/))(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*) 

enter image description here while solves example.com problem, not match youtu.be url.

i have tried regex because think problem youtu.be has slash , directly after, id.

(youtube.com\/)(youtu.be|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*) 

enter image description here

and tried works youtu.be , not else.

((youtube.com\/)|(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)|(youtu.be\/))([^#\&\?]*) 

enter image description here

how can fix modification?

i've cracked it. verify once.

note: blank group i.e. ()() due easy processing of urls, need consider group[6] give lvighymwrgs.

((you(tu.be\/()()(.*)|tube.com\/(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*)))) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -