I will have the following inputs from which i plan to extract the units
(expected output eg.: g, l, kg, ml, l) and the quantity if present (20 in last input)
0,5g500l1000kg20,5ml20x0,50l (1 l = 1,70 €) zzgl. 3,10€ Pfand
if it's simple case i am doing the following
Input: 500g
console.log("500g".replace(/ *\([^)]*\) */g, "") // remove brackets
.replace(/[0-9]/g, "") // remove number eg. 500
.replace(/\s/g, ""))
output: g ( works )
Input: 0,5g
console.log("0,5g".replace(/ *\([^)]*\) */g, "") // remove brackets
.replace(/[0-9]/g, "") // remove number eg. 500g
.replace(/\s/g, ""))
output: ,g ( breaks )
Input: 20x0,50l (1 l = 1,70 €) zzgl. 3,10€ Pfand
console.log("20x0,50l (1 l = 1,70 €) zzgl. 3,10€ Pfand".replace(/ *\([^)]*\) */g, "") // remove brackets
.replace(/[0-9]/g, "") // remove number eg. 500g
.replace(/\s/g, ""))
output: x,lzzgl.,€Pfand ( breaks )