$re = '/(?:https?:\/\/)?(?:[-\w_\.]{2,}\.)?([-\w_]{2,}\.[a-z]{2,4})(?:\/\S*)?/i';
$str = 'minotopia.me
https://minotopia.me/ci/forum/index.php?yolo
https://bugs.nowak-at.net/view.php?id=1337
wow.such.bugs.nowak-at.net/yolo
https://some.very.long.url/with/path/and?query
https://goo.gl/fusgasdfhsk
http://unsecure.site/some/path/with?parameters=yay
HTTPS://LOL.AD-FILTER-BYPASS.tv
https://hitbox.tv/Letsklay
https://minetime.me
minetime.me
hitbox.tv
Yes. At any rate
This is a text with minotopia.me a URL
Hey, check out this awesome site: https://google.com/
!!! HOINED MEINEN SERVER !!! factions.minecraft.to
';
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