C Christian Staffe Nov 5, 2004 #1 What would be the exact regular expression to match GMT strings like "GMT", "GMT+01:30", "GMT-02:00", GMT+05:45... Christian
What would be the exact regular expression to match GMT strings like "GMT", "GMT+01:30", "GMT-02:00", GMT+05:45... Christian
M Matt Redmond Nov 5, 2004 #3 My earlier would have worked but would have matched if there were multiple +/- signs. Sorry, get rid of the * --> GMT[+-]\d{2}:\d{2} This reads: Match the literal string 'GMT', followed by either of + or -, followed by two digits, followed by a colon, followed by two digits.
My earlier would have worked but would have matched if there were multiple +/- signs. Sorry, get rid of the * --> GMT[+-]\d{2}:\d{2} This reads: Match the literal string 'GMT', followed by either of + or -, followed by two digits, followed by a colon, followed by two digits.
J Justin Rogers Nov 6, 2004 #4 hypens in character classes represent ranges... Probably should escape it. GMT[+\-]\d{2}:\d{2} Optionally you can further validate the numbers GMT[+\-](?:[0][0-9]|[1][0-2])... etc... Several postings on numeric range validations if you care to not only parse, but validate with your expressions. http://blogs.regexadvice.com/justin_rogers/category/150.aspx
hypens in character classes represent ranges... Probably should escape it. GMT[+\-]\d{2}:\d{2} Optionally you can further validate the numbers GMT[+\-](?:[0][0-9]|[1][0-2])... etc... Several postings on numeric range validations if you care to not only parse, but validate with your expressions. http://blogs.regexadvice.com/justin_rogers/category/150.aspx