fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var testString = "BP -1.23e4 5.67";
  9.  
  10. var mspaces = @"\s+"; // meaning as many spaces as you want
  11. var cdouble = @"([+\-]?(?:0|[1-9]\d*)(?:\.?\d*)(?:[eE][+\-]?\d+)?)"; // meaning capture a double
  12.  
  13. var shortPattern = String.Join("", "BP", mspaces, cdouble, mspaces, cdouble);
  14. var longPattern = String.Join("", "BP", mspaces, cdouble, mspaces, cdouble, mspaces, cdouble, mspaces, cdouble);
  15.  
  16. var bpShort = Regex.Match(testString, shortPattern, RegexOptions.IgnoreCase);
  17. var bpLong = Regex.Match(testString, longPattern, RegexOptions.IgnoreCase);
  18.  
  19. if (bpLong.Success)
  20. {
  21. Console.WriteLine("Long pattern detected"); // !!FALSE-MATCH!!
  22. }
  23. if (bpShort.Success)
  24. {
  25. Console.WriteLine("Short pattern detected");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.08s 24536KB
stdin
Standard input is empty
stdout
Short pattern detected