$re = '/([\:][\/]{0,2})[\w\-]+([\@]|[\.])?([\w\-]+[\.]){0,}([\w\-]+)?([\:][\d]+)?[\/]?/';
$str = 'https://user_test-teste@regex101.com:80/
http://localhost:80/
https://tools.ietf.org/html/rfc3986#page-7
https://translate.google.com.br/#en/pt/that%20what
https://www.google.com.br/search?client=firefox-b&biw=1920&bih=1001&q=overload+inexistent+property+php&oq=overload+inexistent+property+php&gs_l=psy-ab.3..33i22i29i30k1.36919.57166.0.57324.38.36.2.0.0.0.682.3958.14j18j5-1.33.0....0...1.1.64.psy-ab..3.27.3324...0j35i39k1j0i131k1j0i67k1j0i10k1j0i22i30k1j33i160k1j33i21k1.m5dBRh4nQ-I';
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