HOW TO:從 URL 擷取通訊協定和通訊埠編號
更新:2007 年 11 月
下列範例使用 Match.Result,從 URL 中擷取通訊協定和通訊埠編號。
範例
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