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
Regular Expression to detect URLS
Moderator: General Moderators
-
phpcoder24july
- Forum Newbie
- Posts: 3
- Joined: Sun Jul 24, 2011 12:24 pm
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: Regular Expression to detect URLS
Try this one:
[text]$re = '%\bhttps?://\S+\.(?:jpg|png|gif|mp3|mp4|3gp)\b%i';[/text]
[text]$re = '%\bhttps?://\S+\.(?:jpg|png|gif|mp3|mp4|3gp)\b%i';[/text]
-
phpcoder24july
- Forum Newbie
- Posts: 3
- Joined: Sun Jul 24, 2011 12:24 pm
Re: Regular Expression to detect URLS
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.
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
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
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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
phpcoder24july
- Forum Newbie
- Posts: 3
- Joined: Sun Jul 24, 2011 12:24 pm
Re: Regular Expression to detect URLS
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
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