parse youtube video id using preg_match
- by Webbo
Hi,
I am attempting to parse the video ID of a youtube URL using preg_match. I found a regular expression on this site that appears to work;
(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&\n]+|(?<=v=)[^&\n]+
As shown in this pic; http://i.imgur.com/SQJW2.jpg
My PHP is as follows, but it doesn't work (gives Unknown modifier '[' error)...
<?
$subject = "http://www.youtube.com/watch?v=z_AbfPXTKms&NR=1";
preg_match("(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&\n]+|(?<=v=)[^&\n]+", $subject, $matches);
print "<pre>";
print_r($matches);
print "</pre>";
?>
Cheers