次の方法で共有


方法 : 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

参照

その他の技術情報

.NET Framework の正規表現