I have this an example:
const str = "Icecream, Milk, vanilla syrup, ice cubes20.0 SR180 calories"
I need a way to get the 20.0 from the string, it is always positioned before SR
I tried to convert the string to array like so:
const strArr = str.split(' ');
and try to get the index of the object contain SR
const index = strArr.map((object) => object).indexOf('SR');
But it showed me a result of -1
I was thinking to get the element by index - 1 to have the result of 20.0
Any other ideas, how to make it properly?
Thanks
str.match(/([\d\.]+) SR/)[1]/(\d+(\.\d+)?) SR/