I have the following output:
time = 15:40:32.81
And I want to eliminate : and the . so that it looks like this:
15403281
I tried doing a
time.gsub(/\:\s/,'')
but that didn't work.
time = '15:40:32.81'
numeric_time = time.gsub(/[^0-9]+/, '')
# numeric_time will be 15403281
[^0-9] specifies a character class containing any character which is not a digit (^ at the beginning of a class negates it), which will then be replaced by an empty string (or, in other words, removed).
(Updated to replace \d with 0-9 for clarity, though they are equivalent).
\D could have been used instead of the character class, for that matter.