fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var strs = new String[] {"GMT-05:00 Eastern Time(Toronto)","(GMT - 06:00) Central Time(US, Canada)","GMT-10:00 Hawaii - Aleutian Standard Time(Honolulu)"};
  12. foreach (var s in strs)
  13. {
  14. var result = Regex.Match(s, @"\bGMT\s*([-+]?)\s*(\d+:\d+)");
  15. if (result.Success) {
  16. Console.WriteLine($"Parsing '{s}'\nResult: {result.Groups[1].Value}{result.Groups[2].Value}");
  17. }
  18. }
  19. }
  20. }
Success #stdin #stdout 0.06s 21224KB
stdin
Standard input is empty
stdout
Parsing 'GMT-05:00 Eastern Time(Toronto)'
Result: -05:00
Parsing '(GMT - 06:00) Central Time(US, Canada)'
Result: -06:00
Parsing 'GMT-10:00 Hawaii - Aleutian Standard Time(Honolulu)'
Result: -10:00