Regular expression for matching URLs
Based on this gist by Diego Perini.
composer require ippey/url-regex
<?php
require_once('vendor/autoload.php');
use Ippey\UrlRegex;
// true
$result = Ippey\UrlRegex::isMatch('This contains URL. http://www.google.com');
// false
$result = Ippey\UrlRegex::isMatch('This contains no URL.');
// array('http://www.google.com')
$result = Ippey\UrlRegex::match('This contains URL. http://www.google.com');
// array()
$result = Ippey\UrlRegex::match('This contains no URL.');
// array('https://www.google.co.jp/?q=github', 'https://www.github.com')
$result = Ippey\UrlRegex::match('This contains URL. https://www.google.co.jp/?q=github and https://www.github.com');
MIT