using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^r\s(?P<nickname>\b\S+\b).*\n
^s\b.*?(?P<type>\bGuard\b).*\n
^v.*\n
^w\s.*?(?P<bandwidth>\b[0-9]+\b)";
string input = @"r Tor4ever AAcif1htILdru0BO0qX7OwGVhAU oHlbWBdaN3+QSleqBVL9/yAdcRs 2014-07-31 21:42:43
s Exit Fast Guard HSDir Running V2Dir Valid
v Tor 0.2.4.21
w Bandwidth=231
p reject 25,119,135-139,445,563,1214,4661-4666,6346-6429,6699,6881-6999
r Tornin AA8YrCza5McQugiY3J4h5y4BF9g vNRd1kyQ0i9UsVwYq5YFPHJi3jw 2014-08-01 00:26:18
s Fast Guard HSDir Named Running Stable V2Dir Valid
v Tor 0.2.4.23
w Bandwidth=713
p reject 1-65535";
RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx