$re = '/^(?:https?:\/\/)?(?:www\.)?[\d\w\.-]+(?:\.|:)(?:[a-z\.]{2,6}|\d+)\/?.*$/mi';
$str = 'https://regex101.com/
https://www.variables.sh/complex-regular-expression-examples
https://search.brave.com/search?q=regex+challenges&source=desktop
https://web.whatsapp.com/
https://www.youtube.com/watch?v=fc_RvxTtIwc
https://text-auditor.netlify.app/
https://github.com/Dashrath-Sharma
http://github.com/Dashrath-Sharma
https://onecompiler.com/javascript/3zqzyu2g4
http://localhost:3000/
https://www.codingame.com/clashofcode/clash/report/3342454a92e4c660d772438bac8b2ef73de3c8f
https://react.dev/learn/thinking-in-react
https://dapp-world.com/course/introduction-to-solidity-Ynws/working-of-traditional-dapps-compared-to-dapps/reading
http://www.google.com
https://www.google.com
http://google.com
https://google.com
http://www.google.com/
https://www.google.com/
http://google.com/
https://google.com/
http://www.google.com/index.html
https://www.google.com/index.html
http://google.com/index.html
https://google.com/index.html
';
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