$re = '/^(((https|http):\/\/)?([a-z0-9@:%._\+~#=]{1,256}\.)+[a-z0-9:()]{1,20}+(\/[a-z0-9_():@.]+)*(\/)?((\?|#).*)?|(website_not_available))/m';
$str = 'http://foo.com/blah_blah
http://foo.com/blah_blah/
http://foo.com/blah_blah_(wikipedia)
http://foo.com/blah_blah_(wikipedia)_(again)
http://www.example.com/wpstyle/?p=364
https://www.example.com/foo/?bar=baz&inga=42&quux
http://✪df.ws/123
xzcz
xzcxzvcxzvxczc
suva
www.https//:fgdv.com
test.https://www.xflowpay.com
http://fr.wikipedia.org/wiki/%C3%89l%C3%A9phant
www.exldfcsdf/dcsdfv
http://userid:password@example.com:8080
http://userid:password@example.com:8080/
http://userid@example.com
http://userid@example.com/
http://userid@example.com:8080
http://userid@example.com:8080/
http://userid:password@example.com
http://userid:password@example.com/
http://142.42.1.1/
http://142.42.1.1:8080/
http://➡.ws/䨹
http://www.mysite.com/myresumé.html
http://foo.com/blah_(wikipedia)#cite-1
http://foo.com/blah_(wikipedia)_blah#cite-1
http://code.google.com/events/#&product=browser
http://foo.com/unicode_(✪)_in_parens
http://foo.com/(something)?after=parens
http://code.google.com/events/#&product=browser
ftp://foo.bar/baz
http://j.mp
http://foo.bar/?q=Test%20URL-encoded%20stuff
http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com
http://1337.net
http://a.b-c.de
http://223.255.255.254
https://foo_bar.example.com/
https://regex101.com/
http://
http://.
http://../
http://##
///a
http:///a
foo.com
rdar://1234
http:// shouldfail.com
h://test
http://foo.bar/foo(bar)baz quux
http://10.1.1.255
http://-a.b.co
http://a.b--c.de/
ftps://foo.bar/
http://3628126748
http://.www.foo.bar./
http://www.foo.bar./
http://.www.foo.bar/
http://10.1.1.254
fghfg';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php