$re = '/^(?:[a-z][0-9a-z-.+]*:\/\/)?((?:(?:[a-z\u00a1-\uffff0-9_]+-?)*[a-z\u00a1-\uffff0-9_]+)(?:\.(?:[a-z\u00a1-\uffff0-9_]+-?)*[a-z\u00a1-\uffff0-9_]+)*(?:\.(?:[a-z0-9\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/.*)?(?:\?.*)?(?:\#.*)?$/mi';
$str = 'socks://www.example.com
10.1.1.1
10.1.1.2/4
10.1.1.3/0
10.1.1.0/8
10.1.1.5/32
10.1.1.6/35
10.1.1.7/36000
10.1.1.8/abcd
10.1.1.9-10.1.1.10
user:pass@zxuz.com
user@proxy.brew.opendnstest.com/customBlockUserInfo
user:@proxy.brew1.opendnstest.com/customBlockUserInfo
user:password@proxy.brew2.opendnstest.com/customBlockUserInfo
ftp://cnn.example.com&story=breaking_news@foobar.com/top_story.htm
foo.com:8080/bar/baz
asdfasdf.com/foo/b%20ar
https://example.com/archive/*/http://somesite.com
';
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