using System; using System.Text.RegularExpressions; public class Test { public static void Main() { var testString = "BP -1.23e4 5.67"; var mspaces = @"\s+"; // meaning as many spaces as you want var cdouble = @"([+\-]?(?:0|[1-9]\d*)(?:\.?\d*)(?:[eE][+\-]?\d+)?)"; // meaning capture a double var shortPattern = String.Join("", "BP", mspaces, cdouble, mspaces, cdouble); var longPattern = String.Join("", "BP", mspaces, cdouble, mspaces, cdouble, mspaces, cdouble, mspaces, cdouble); var bpShort = Regex.Match(testString, shortPattern, RegexOptions.IgnoreCase); var bpLong = Regex.Match(testString, longPattern, RegexOptions.IgnoreCase); if (bpLong.Success) { Console.WriteLine("Long pattern detected"); // !!FALSE-MATCH!! } if (bpShort.Success) { Console.WriteLine("Short pattern detected"); } } }