using System.Text.RegularExpressions;
public static void Main()
Regex rgx = new Regex("{(.+?)}", RegexOptions.Compiled);
string input = "This {is} a {test}...";
string output = rgx.Replace(input, match =>
string newMatch = match.Groups[1].Value;
return ">> " + newMatch + " <<";
Console.WriteLine(output);
input = "http://www.contoso.com:8080/letters/readme.html";
rgx = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",
RegexOptions.None, TimeSpan.FromMilliseconds(150));
Match m = rgx.Match(input);
string proto = m.Result("${proto}");
string port = m.Result("${port}");
Console.WriteLine(proto + ":" + port);
Console.WriteLine(m.Result("${proto}:${port}"));
input = "ws://127.0.0.1:8000/server.php";
rgx = new Regex(@"^(?<proto>\w+)://(?<host>\w+.\w+.\w+.\w+):(?<port>\d+)?/(?<path>\w+.\w+)",
RegexOptions.None, TimeSpan.FromMilliseconds(150));
string proto = m.Result("${proto}");
string host = m.Result("${host}");
string port = m.Result("${port}");
string path = m.Result("${path}");
Console.WriteLine("Proto: " + proto + " Host: " + host + " Port: " + port + " Path: " + path);