note 26010 added to function.preg-match
| From: | vectorpup at hotmail dot com | Date: | Tue, 15 Oct 2002 07:27:42 +0000 |
| Subject: | note 26010 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38090@lists.php.net to get a copy of this message | ||
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
--
http://www.php.net/manual/en/function.preg-match.php
http://master.php.net/manage/user-notes.php?action=edit+26010
http://master.php.net/manage/user-notes.php?action=delete+26010
http://master.php.net/manage/user-notes.php?action=reject+26010