fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string sInput = " foo@bar.com , baz@acme, bill@bing.co.uk ,inv liad , thing ";
  10. MatchCollection mc = Regex.Matches(
  11. sInput,
  12. @"\b[^,]+\b|[ ,]+"
  13. );
  14. foreach( Match m in mc)
  15. {
  16. Console.WriteLine($"({m.Index}, {m.Length}) |{m.Value}|");
  17. }
  18. }
  19. }
Success #stdin #stdout 0.03s 134592KB
stdin
Standard input is empty
stdout
(0, 2) |  |
(2, 11) |foo@bar.com|
(13, 4) |  , |
(17, 8) |baz@acme|
(25, 2) |, |
(27, 15) |bill@bing.co.uk|
(42, 2) | ,|
(44, 8) |inv liad|
(52, 3) | , |
(55, 5) |thing|
(60, 2) |  |