$re = '/http(?:s)?:\/\/(?:www\.)?youtube\.com\/.*?watch%3Fv%([\d\w-_]+)/';
$str = 'http://youtube.com/attribution_link?a=r_FgjB-RKNo&u=/watch%3Fv%3DB0_X8zWJd0Q%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=1crTn2Lx38I&u=/watch%3Fv%3DHhebhh2s5d4%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=_zMgiznzBto&u=/watch%3Fv%3D-kaoCPvUHJM%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=F8VReY1sT0A&u=/watch%3Fv%3D5RLM9rk0Q8s%26feature%3Dem-uploademail
https://www.youtube.com/watch?feature=player_detailpage&v=2eGUP16P_p4
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php