$re = '/(((ftp|https?):\/\/)[\-\w@:%_\+.~#?,&\/\/=]+)|((mailto:)?[_.\w-]+@([\w][\w\-]+\.)+[a-zA-Z]{2,3})/';
$str = 'The test has some url in the last. extract the text starting from https to the end of the string<br></br>https://xyz.com/index.html some text after http://www.ex.com/test.html there are still more text as like ftp://ftp.test.com , which is also matching. This is a mailto link mailto:guyfromchennai@gmail.com to which you can send mail to contact me.';
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