fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Example
  5. {
  6. public static void Main()
  7. {
  8. string pattern = @"([A-Z0-9]{4})";
  9. string input = @" ; Message Number
  10. ; | Time Offset (ms)
  11. ; | | Type
  12. ; | | | ID (hex)
  13. ; | | | | Data Length
  14. ; | | | | | Data Bytes (hex) ...
  15. ; | | | | | |
  16. ;---+-- ----+---- --+-- ----+--- + -+ -- -- -- -- -- -- --
  17. 1) 2.0 Rx 0400 8 01 5A 01 57 01 D2 A6 02
  18. 2) 8.6 Rx 0500 8 02 C1 02 C9 02 BE 02 C2
  19. 3) 36.2 Rx 0401 8 01 58 01 59 01 01 01 01
  20. 4) 41.7 Rx 01C4 8 27 9C 64 8C 00 03 E8 08
  21. 5) 43.1 Rx 0501 8 02 C0 02 C1 02 C6 02 C0
  22. 6) 62.7 Rx 01C2 8 27 9C 60 90 00 0F 04 08 ";
  23. RegexOptions options = RegexOptions.Multiline;
  24.  
  25. foreach (Match m in Regex.Matches(input, pattern, options))
  26. {
  27. Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
'0400' found at index 406.
'0500' found at index 476.
'0401' found at index 546.
'01C4' found at index 616.
'0501' found at index 686.
'01C2' found at index 756.