fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string pattern = @"(?im)^Invoice[\p{Zs}\t]+Nr\.?\s*(?<arvenumber>[^\W_]+)[\s_]";
  9. string input = @"...
  10. Some nr_11687767_ other 101308591
  11. Invoice Nr.
  12. M230714_some text
  13. Kirjeldus
  14. ...
  15. Sometimes it is terminated by newline
  16.  
  17. ...
  18. This nr_11687767_KMKR_EE101308591
  19. Invoice Nr.
  20. M230714
  21. 01.05.2023
  22. Item
  23. ...
  24. or by other white space delimiter :
  25.  
  26. ...
  27. Some nr_11687767_ Text
  28. Invoice Nr M230714 Date 01.05.2023
  29. Desc
  30. ...";
  31.  
  32. foreach (Match m in Regex.Matches(input, pattern))
  33. {
  34. Console.WriteLine("'{0}' found", m.Groups["arvenumber"].Value);
  35. }
  36. }
  37.  
  38. }
Success #stdin #stdout 0.08s 25556KB
stdin
Standard input is empty
stdout
'M230714' found
'M230714' found
'M230714' found