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
Hard/Easy Regular Expression help
Moderator: General Moderators
-
pauper2thedemon
- Forum Newbie
- Posts: 1
- Joined: Tue Aug 10, 2010 8:03 am
Re: Hard/Easy Regular Expression help
I would use filter_var personally
http://www.php.net/manual/en/book.filter.php
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';
}