$re = '/((:?.*):(.*\..*@.*\.com:.*))/m'; $str = 'https://template.com/x/xxxx/string:temp.late@xxxx.com:xxxx'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);