How to add a 0 before a field, with a condicion?

Hello!
I have different docs with different hours from 0 to 23 like the following
{
"date" : "2022-06-23",
"eventDate" : "2022",
"StoreID" : 190,
"hour" : 0,
"PosID" : 12,
"tempo" : 0.0
}
{
"date" : "2022-06-23",
"eventDate" : "2022",
"StoreID" : 190,
"hour" : 1,
"PosID" : 12,
"tempo" : 0.0
}
For the field hour, i need to add a 0 before the number if its below 10.
I tried different methods like this:
ruby {
code => '
if event.get('hour') =~ /^\d{1}$/
event.set('hour', '0'+event.get('hour'))
end
'
}
but gives me an error
What can I do?

If you use single quotes to surround the code then within the code you must use double quotes.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.