开发者

Need a regex that matches URLs with/without http:// or www. or http://www. in a text

开发者 https://www.devze.com 2023-01-10 15:45 出处:网络
I\'ve been trying to find a solution myself but I couldnt do it so far (even tried all regexlib.com suggestions)开发者_如何转开发, so:

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


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?


How about this?

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

精彩评论

暂无评论...
验证码 换一张
取 消