Posted by John Dunlop on 11/30/07 14:39
Charles:
> I'm trying to extract the home page URL out of a any URL from the same
> web site
> For instance if I'm onhttp://www.regular-expressions.info/javascriptexample.html
> I want to extracthttp://www.regular-expressions.info
If you know your subject string is a well-formed URL then use the
regular expression from RFC3986:
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
$1 and $3 give you the scheme and authority, e.g., http://host.invalid
http://www.apps.ietf.org/rfc/rfc3986.html
--
Jock
Navigation:
[Reply to this message]
|