fork(12) download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var strs = new List<string> {"abcd@efg.com this is just some text. these are just some numbers 123456 xyz@xyz.com asdasd asdad",
  10. "abcd@efg.com mnop@qrs.com This is just some text. these are just some numbers 123456 xyz@xyz.com asdasd asd",
  11. "abcd@efg.com mnop@qrs.com uvw@xyz.com This is just some text. these are just some numbers 123456 xyz@xyz.com asdad" };
  12. foreach (var s in strs)
  13. {
  14. var results = Regex.Matches(s, @"(?i)\G\s*([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6})")
  15. .Cast<Match>()
  16. .Select(x => x.Groups[1].Value);
  17. Console.WriteLine(string.Join(", ", results));
  18. }
  19.  
  20. }
  21. }
Success #stdin #stdout 0.09s 20720KB
stdin
Standard input is empty
stdout
abcd@efg.com
abcd@efg.com, mnop@qrs.com
abcd@efg.com, mnop@qrs.com, uvw@xyz.com