$re = '/(?(DEFINE)(?\'cont\'(htt(ps|p)|(sft |ft)(ps|p)|ss(l|h)|smb|git|network|file|smtp|vnc))(?\'pg\'(?<port>\:[0-3][0-5][0-5][0-6][0-5])|(?<gitusr>\:[a-zA-Z0-9\-]{3,39}))) (?<pro>(?P>cont)\:\/\/)(?<dom>[[:alnum:]]+\.[[:alnum:]]+\.[[:alnum:]]{2,6})(?P>pg){0,1}(?<fp>\/[[:print:]]+\/){0,}(?<file>[[:graph:]]+\.[[:alnum:]]{1,6}){0,1}/x';
$str = 'http://raw.githubusercontent.com:3/FlagB&rew/Sharkive/master/3ds/000400ddddddddddddddddddddddddddd.dddddd
git@github.com:yorha93/shell-scripts.git';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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