using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"^The thing is.*\b(S\d)(?!.*\b(?:blue|red)\b)";
string input = @"TRUE
The thing is S2w697 and green
The thing is S2e697 and yellow
The thing is S2b697 and pink
FALSE
The thing is S25697 and blue
The thing is S256b7 and red
The thing is S2e697 and blue thing
The thing is S2b697 and red thing";
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