using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?m)(?P<head>^tacacs[\s|-]server\shost\s)(?P<ipv4>(\d+\.){3}\d+)(?P<key>\skey\s[0-9]\s\S[a-zA-Z0-9]+\S)?(?P<tail>(.*))";
string substitution = @"";
string input = @"aaa group server tacacs+ tacacs
server 172.26.60.235
server 172.24.248.209
source-interface mgmt0
aaa group server tacacs+ TACACS-GROUP
server 172.26.60.235
source-interface mgmt0
aaa group server tacacs+ TACACS-TEST1
server 172.26.60.235
server 172.24.248.209
aaa group server tacacs+ tacacs+group
source-interface mgmt0
ip tacacs source-interface mgmt0
tacacs-server host 172.26.60.235 key 7 ""Foihmr3"" timeout 5
tacacs-server host 172.24.248.209 key 7 ""Foihmr3""
tacacs server host 172.24.248.209 key 7 ""Foihmr3""
tacacs-server host 172.26.60.235 timeout 5
tacacs-server host 172.26.60.235
tacacs-server host 172.24.248.209";
RegexOptions options = RegexOptions.Multiline;
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);
}
}
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