tags:

views:

43

answers:

2

I've been trying to find a solution myself but I couldnt do it so far (even tried all regexlib.com suggestions), so:

Need a regex that matches URLs like (PHP code):

http://example.com orhttp://www.example.com or www.example.com example.com

+1  A: 

How about this?

(www|http:\/\/|https:\/\/)?([.[:alnum:]-]){0,4}([[:alnum:]-]+.)([[:alnum:]_-].?)([[:alpha:]]){0,3}

0x90
A: 

I've been trying to use this one (catch http://(optional)www.example.com/path/otherpath):

$regex = "/(((ftp|https?):\/\/www.)|(www.)|(http:\/\/))([\d\w-.]+?)+(:\d+)?(\/([\w\/,=]*(\?\S+)?)?)?/";

but it's not enough.

Still missing the example.com. Any suggestion?

Davi Bandeira