using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\x1B\[(?:[0-9]{1,3}(?:;[0-9]{1,3})?)?[mGK]";
string input = @"Summary [0m
Accounts:
Name Account ID Title
----------------------------------------------- ------------ -----------------------------------------------
[32maccount-accountType-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-gamma
[32maccount-accountType-e2e-gamma[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-gamma
Summary [0m
Accounts:
Name Account ID Title
---------------------------------------------- ------------ ----------------------------------------------
[32maccount-accountType-e2e-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-e2e-prod
[32maccount-accountType-prod[0m [38;2;128;128;128m123456789012[0m account-accountType-prod";
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