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 #<MatchData “Oct 22 06:25:35” 1:“22” 2:“06:25:35”>
It should return #<MatchData “Oct 22 06:25:35” 1:“22” 2:“03:25:35”>
Instead of #<MatchData “Oct 22 06:25:35” 1:“22” 2:“06:25:35”>
It should return #<MatchData “Oct 22 06:25:35” 1:“22” 2:“03:25:35”>
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 class Time - RDoc Documentation) and then
offset it as you need.
It should return #<MatchData “Oct 22 06:25:35” 1:“22” 2:“03:25:35”>
You don’t want to mess with what the regexp match returns. Rather you
need to process results afterwards. And please also consider the other
comments.
Kind regards
robert
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.