Page 1 of 1

Hard/Easy Regular Expression help

Posted: Sat Jul 31, 2010 12:43 am
by M.A.G
Hello Everyone,

I need help to get regular expressions to match urls in that way.

Used language: PHP

First One:-

(http:// only works with http protocol) (with www or without) (dot.) (domain name what ever it has numbers or chars) (dot.) (com|org|us etc...any domain extension is accept)(/ must have slash)(Numbers Only)(/ with ending slash or without)

examples:-

http://www.example.com/123123

http://example.us/41233/

http://www.example.info/41233/



The second one which I believe its hard to done:-

(http:// only works with http protocol) (with anything here numbers and chars www2 ww4 links etc ..) (dot.) (domain name what ever it has numbers or chars) (dot.) (com|org|us etc...any domain extension is accept)(/ must have slash)(foldername maybe having a folder name or not)(any-file-name.php?((url|link|redirect|go|anything=(what ever comes here)

examples:-

http://www.example.com/dir/red.php?url= ... xample.com

http://example.us/out.php?link=http://www.example.com

http://example.biz/go/to/dir/exit.php?h ... 8xMDc2NzA=

http://links.example.biz/go/to/dir/exit ... 8xMDc2NzA=



Your time and effort is much appreciated and I'm looking forward for your help.



Best Regards,

M.A.G

Re: Hard/Easy Regular Expression help

Posted: Thu Aug 05, 2010 9:07 am
by M.A.G
Anyone?

Re: Hard/Easy Regular Expression help

Posted: Tue Aug 10, 2010 8:06 am
by pauper2thedemon
I would use filter_var personally

http://www.php.net/manual/en/book.filter.php

Code: Select all

<?php

$url = 'http://www.some-example.com/url/here';
$url = filter_var( $url, FILTER_VALIDATE_URL );

if( $url === FALSE ){
   echo 'url is not valid';
}