Reputation: 2563
I need help with a regex pattern to match 2 urls? The code I currently have matches the 1st url, but how would I make one pattern to match both urls. I am trying to obtain the random characters at the very end of each url.
http://www.videozer.com/video/yKKd
http://www.videozer.com/watch_video.php?v=rbgsd
preg_match('/http\:\/\/((www\.)?)videozer\.com\/video\/([a-zA-Z0-9]+)/', $URL, $result);
Upvotes: 1
Views: 2271
Reputation: 39356
preg_match('@http://(?:www\.)?videozer\.com/(?:video/|watch_video\.php\?v=)([a-zA-Z0-9]+)@', $URL, $result);
(abc|def)
to match either the string 'abc' or 'def'/
Upvotes: 3
Reputation: 11610
You would just use matching groups. You can see the result here.
preg_match('/http\:\/\/((www\.)?)videozer\.com\/(video\/|watch_video\.php\?v=)([a-zA-Z0-9]+)/', $URL, $result);
Upvotes: 0
Reputation: 1114
This should do it:
preg_match('/http\:\/\/((www\.)?)videozer\.com\/(video\/|watch_video\.php\?v=)([a-zA-Z0-9]+)/', $URL, $result);
Upvotes: 1