Page 1 of 1

Regular Expression to detect URLS

Posted: Sun Jul 24, 2011 12:40 pm
by phpcoder24july
Hi everyone,

I am looking for a regular expression which can extract URLS with extension(jpg,png,gif,mp3,mp4,3gp).
At present I have this one $reg_exUrl = "!(http|https)://([a-z0-9A-Z\-\.\/\_\:\@]+\.(?:jpe?g|png|gif|mp3|mp4|3gp))!Ui"
It works well but for this url=http://190.230.80.163:8080/movies/67702 ... 80.163.3gp
It only detects http://190.230.80.163:8080/movies/677025542@190.230

I tried one more $reg_exUrl = "/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z0-9]{2,3}(\/\S*)?/"
this gives http://190.230

Any help would be appreciable.
Thanks

Re: Regular Expression to detect URLS

Posted: Mon Jul 25, 2011 7:58 pm
by ridgerunner
Try this one:

[text]$re = '%\bhttps?://\S+\.(?:jpg|png|gif|mp3|mp4|3gp)\b%i';[/text]

Re: Regular Expression to detect URLS

Posted: Tue Jul 26, 2011 2:18 am
by phpcoder24july
Thanks for your reply.
I am getting the same result http://190.230.80.163:8080/movies/677025542@190.230
for http://190.230.80.163:8080/movies/67702 ... 80.163.3gp. For others
its working fine. Anything else to try. I urgently need this one.
Thanks.

Re: Regular Expression to detect URLS

Posted: Tue Jul 26, 2011 3:17 pm
by pickle
What are you running this on? A long string? Or are you just trying to identify which URLs in a list end in the extensions you want?

In any case, I've found with regular expressions that you should only specify what you absolutely need to. For example, is it necessary to specify "://([a-z0-9A-Z\-\.\/\_\:\@]" ?

This regex works in with the short string I've been testing:
[syntax]!(http.*[3gp|jpg|gif|png|mp3|mp4])![/syntax]

Testing string:
oaeuaoeuhttp://190.230.80.163:8080/moviesjpg/677025542@190.230.80.163.jpgaoeuaoeu

Re: Regular Expression to detect URLS

Posted: Wed Jul 27, 2011 4:13 pm
by phpcoder24july
Actually I need to parse the body of an email to extract all
the urls with extension (mp3,3gp,mov,avi,wmv,jpg,png etc).

You can have a look at this
$text = "hello.. how are you?? are you keeping well?? please checkout this url
http://190.230.80.160:8080/movies/67702 ... 80.160.3gp
http://dailywallpaper.files.wordpress.c ... 00.jpg..//
!??? this is the logo http://s.ytimg.com/yt/img/email_logo_no_tagline.png?? ?
http://190.230.80.160/ISC/Ressources/AF_KLM/afklm.mp4 ./......plj/http://v6.cache2.c.bigcache.googleapis. ... 775554.jpg ";

The regular expressions I have used are working fine for all of the above urls except the first one
in the $text. First one I get only this http://190.230.80.160:8080/movies/677025542@190.230

Thanks