You can do something like this using string manipulation that doesn't require regular expressions. E.g., you can take the part of the string form of the URL after a "//" and before a "/":
select ?url ?hostname {
values ?url { <http://example.org/index.html> }
bind(strbefore(strafter(str(?url),"//"),"/") as ?hostname)
}
---------------------------------------------------
| url | hostname |
===================================================
| <http://example.org/index.html> | "example.org" |
---------------------------------------------------
That doesn't use regular expressions, and might be faster than a solution using the regex function.
However, this might still get you more than a hostname, e.g., if the URL is something like http://username:password@example.org:8080, where you'd get username:password@example.org:8080, which is more than just hostname.
To do this more carefully, you'd want to pick one of the URI/URL, etc., specifications, such as RFC 3986, and have a look at the section on syntax components. A few relevant productions from that grammar are:
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
hier-part = "//" authority path-abempty
/ path-absolute
/ path-rootless
/ path-empty
The authority component is preceded by a double slash ("//") and is
terminated by the next slash ("/"), question mark ("?"), or number
sign ("#") character, or by the end of the URI.
authority = [ userinfo "@" ] host [ ":" port ]
I won't work through all that (and maybe it would make more sense to use a regular expression to handle the complex cases), but it might be easiest to just take the URI from the SPARQL result and then use an actual URI parsing library to get the hostname. That's the most reliable solution, since URIs can be pretty complex.