.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=)([^#\&\?]*) 
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=)([^#\&\?]*)
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=)([^#\&\?]*) 
and tried works youtu.be , not else.
((youtube.com\/)|(v\/|u\/\w\/|embed\/|watch\?v=|\&v=)|(youtu.be\/))([^#\&\?]*) 
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
Post a Comment