Just wondering how I can extract or match the specific file type, since there are a lot of malformed URLs and directories.
So I need a good regex to match only the real ones.
http://domain.com/1/image.jpg <-match .jpg
http://domain.com/1/image_1.jpg/.gif <-match first .jpg
http://domain.com/1/image_1.jpg/image.png <-match first .jpg
http://domain.com/1/image_1.jpg <-match .jpg
http://domain.com/1/image.jpg.jpeg <-match only the first .jpg
http://domain.com/1/.jpg <-not match
http://domain.com/.jpg.jpg <- not match
/1/.jpg <-not match
/.jpg.png <-match the first jpg
/image.jpg.png <-match the first jpg
I'm trying with this piece of code:
preg_match_all('([a-zA-Z0-9.-_](jpg))i', $url, $matches);
Any ideas?