Regex to replace timezone offset

regex, ruby, ruby-on-rails

Solution

"2012-04-17T15:40+05:30".gsub!(/[+-]\d\d:\d\d/, '+00:00')

will replace both positive and negative offsets. But why?

Problem

I have a string representing date/time with timezone. I want to change the timezone part to UTC that is `+00:00` Please help me to write regext to match `+05:30`, `-03:30` etc and replace it with `+00:00` I tried with `"2012-04-17T15:40+05:30".gsub!(/\+\d\d:\d\d/, '+00:00')` which gives me expected results but I don't know how to match `-5:30` I would appreciate if someone helps me to write regex which work with both `2012-04-17T15:40+05:30` and `2012-04-17T15:40-05:30` Thanks, Amit Patel

Original source