1๐
โ
Use this regex: /[0-9]+\,?[0-9]*/g
Then you can convert the ,
chars to .
// Example
const input = '2,5kg meal 500g cookie'
const floats = input
.match(/[0-9]+\,?[0-9]*/g)
.map(a => parseFloat(
a.replace(',','.')
)
)
// floats => [2.5, 500]
Source:stackexchange.com