For port number testing purpose I am passing the following URL, but it throws an exception, exception itself is null - no descriptive information
testURL = "ce-34-54-33.compute-1.amazonaws.com:";
Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?:(?<port>\d+)?/",
RegexOptions.None, TimeSpan.FromMilliseconds(150));
// the following throws an exception
int port = Int32.Parse(r.Match(testURL).Result("${port}"));
Update:
If I use System.Uri
, the value always -1 no matter whether or not I include port.
Uri uri = new Uri(connectionURL);
int value = uri.Port;