I have a string time format like this:
This is pretty basic using
str = "d-m-Y H:i" str.gsub(/[a-z]/i, '%\0') # => "%d-%m-%Y %H:%i"
In the replacement string
\0 represents the entire match, which in this case is the matched letter, so this says, "Replace each letter with a
% followed by the letter."