// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text.RegularExpressions; namespace E { public class MainClass { private static Regex re = new Regex(@"([a-z]+)(?:://)((([\w]+):([\w]+)@)|)([\w-\.]+)((/[\w\-/\.]*)|)"); public static void Test(string url) { Match m = re.Match(url); string protocol = m.Groups[1].Value; string user = m.Groups[4].Value; string pass = m.Groups[5].Value; string host = m.Groups[6].Value; string path = m.Groups[8].Value; Console.WriteLine("URL = " + url); Console.WriteLine("protocol = " + protocol); Console.WriteLine("user = " + user); Console.WriteLine("pass = " + pass); Console.WriteLine("host = " + host); Console.WriteLine("path = " + path); } public static void Main(string[] args) { Test("http://www.eksperten.dk"); Test("http://adminuser:adminpass@www.myplace.dk"); Test("https://www.eksperten.dk"); Test("http://www.eksperten.dk/spm/770525"); Console.ReadLine(); } } }