从字符串中获取所有网址?

I have a string that contain URLs and other texts. I want to get all the URLs in to $matches array. But the following code wouldn't get all the URLs in to $matches array:

$matches = array();
$text = "words cotry.lk and newe.com joemiller.us schoollife.edu hello.net some random news.yahoo.com text http://tinyurl.com/9uxdwc some http://google.com random text http://tinyurl.com/787988 and others will en.wikipedia.org/wiki/Country_music URL";

preg_match_all('$\b[-A-Z0-9+&@#/%?=~_|!:,.;][.]*[-A-Z0-9+&@#/%=~_|(https?|ftp|file)://-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%?=~_|!:,.;]{8,50}$i', $text, $matches);
print_r($matches);

Above code wouldn't show me following URLs:

cotry.lk 
newe.com 

Can you please tell me with an example, how can I modify above code to get all the URLs.

Please note, not all the URLs will contain herf and this string is not obtain from a html file.

import re
def getall_urls(value):
    pattern = '((?:[\w\d]+\:\/\/)?(?:[\w\-\d]+\.)+[\w\-\d]+(?:\/[\w\-\d]+)*(?:\/|\.[\w\-\d]+)?(?:\?[\w\-\d]+\=[\w\-\d]+\&?)?(?:\#[\w\-\d]*)?)'
    # Place matches into list (a.k.a array)
    getall = re.findall(pattern, value) # preg_match_all() function in PHP
    # Remove duplicates and return the result
    return set(getall) if getall else ()

Here is the Python code that do exactly what you need. Expression was originally found on Internet and modified. Although this code is written in Python, you can easily use the expression in PHP as well.

if I were you i would not use preg_match_all, if you want to check the string for valid addresses. Instead i would cut the string into words and run them tough.

filter_var($url, FILTER_VALIDATE_URL)

if it returns true you know its a valid url