using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^(?P<dst_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?,?(?P<User>[a-zA-Z._\d]+),(?P<src_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(?<ID>\d+)";
string input = @"OpenVPN CLIENT LIST
Updated,Thu Nov 11 10:00:15 2021
20.20.20.20,n.y.f_o_o,2.2.2.2:11111 Thu Nov 11 10:00:14 2021
10.10.10.10,a.a.foo,3.3.3.3:22222,Thu Nov 11 10:00:14 2021
Updated,Thu Nov 11 10:00:12 2021
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
30.30.30.30,t.p.bar,192.168.1.1:58348,Thu Nov 11 10:00:12 2021
40.40.40.40,test,192.168.1.11:58348,Thu Nov 11 10:00:02 2021
50.50.50.50,test_2,33.33.33.3:58348,Thu Nov 11 10:00:22 2021";
RegexOptions options = RegexOptions.Multiline;
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