From: Ammar Ali Date: 2010-10-26T23:54:24+09:00 Subject: Re: Change captured values in a regexp On Tue, Oct 26, 2010 at 4:47 PM, Bruno Sousa wrote: > Hi everyone! > Supposing there is a string like this: > Oct 22 06:25:35 machine kernel: [271182.956004] IN= OUT=eth0 > SRC=10.8.0.248 DST=192.5.5.241 > > I am using the following regexp to capture time: > /Oct (\d{2}) (\d{2}:\d{2}:\d{2})/ > > How can I alter the hour value only and keep it in the result returned? > I want to decrease 3 hours. > Instead of # > It should return  # That's not a job for regular expressions. You need to handle this by yourself. Once you have the hour match, convert it into a Time object (see http://ruby-doc.org/core/classes/Time.html#M000305) and then offset it as you need. HTH, Ammar