note 26010 deleted from function.preg-match by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:14:08 +0000 |
| Subject: | note 26010 deleted from function.preg-match by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57398@lists.php.net to get a copy of this message | ||
Note Submitter: vectorpup@hotmail.com
----
The following regex will match almost any http/https URI and break it into its component parts.
It captures protocol(1), auth user(2), auth password(3), hostname(4), path(5), filename(6), file
extension(7) and query(8). All fields may or may not be there (ie: it's a suitable template
for matching URIs in HTML documents for resolution to a fully qualified URL).
Yeesh, but it's long; the PHP.net comment system won't accept it as one line. I'm
going to break it into (?: .. ) boundaries, so just remove the newlines, and reassemble it from
there.
^(?:(http[s]?):\/\/
(?:(.*):(.*)@)?([^\/]+)
)?
((?:[\/])?
(?:[^\.]*?)?
(?:[\/])?)?
(?:([^\/^\.]+)\.([^\?]+)
)?
(?:\?(.+))?$/i