Procedura: estrarre un protocollo e un numero di porta da un URL
Aggiornamento: novembre 2007
Nell'esempio seguente viene utilizzato Match.Result per estrarre un protocollo e un numero di porta da un URL.
Esempio
Dim url As String = "https://www.contoso.com:8080/letters/readme.html"
Dim r As New Regex("^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/", _
RegexOptions.Compiled)
Console.WriteLine(r.Match(url).Result("${proto}${port}"))
' The example displays the following output:
' http:8080
string url = "https://www.contoso.com:8080/letters/readme.html";
Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",
RegexOptions.Compiled);
Console.WriteLine(r.Match(url).Result("${proto}${port}"));
// The example displays the following output:
// http:8080