using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^config (dhcp|dns|router|interface) (?:ip|ipv4|id|bgp|name) (<[^>]*>|(?:\d+\.){3}\d+|[a-z]+ id \d+|\d+)( port| timeout| id|\s*)( <[^>]*>\s*| \d+\s*|\s*)$";
string input = @"config dhcp ip <dhcp-ipaddress> port <dhcp-port-number>
config dhcp ip <dhcp-ipaddress> timeout <time-out-value>
config dhcp ipv4 <dhcp-ipaddress>
config dns ip <dns-ipaddress> port <dns-port-number>
config dns ip <dns-ipaddress> timeout <time-out-value>
config router bgp <bgp-number>
config interface id <interface-id>
config interface name <interface-name> id <interface-id>
config dhcp ip 1.1.1.1 port 8080
config dhcp ip 1.1.1.2 timeout 120
config dhcp ip 1.1.1.1 timeout 120
config dhcp ip 1.1.1.2 port 8080
config dhcp ipv4 1.1.1.3
config interface id 12
config interface name abc id 12
config interface id 13
config interface name xyz id 13
config dhcp ip 1.1.1.1 port 8080
config dhcp ip 1.1.1.1 timeout 120
config dhcp ip 1.1.1.2 timeout 120
config dhcp ip 1.1.1.2 port 8080
config dhcp ipv4 1.1.1.3
config interface id 12
config interface name abc id 12
config interface id 13
config interface name xyz id 13";
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