I need get two values from a string and sum them.
var text = 'SOC 01 672 1.653.806,08 18.512,98 1.667.621,57 2.647,38 07 23 12.965,11 0,00 12.965,11 0,00 13 5 10.517,81 0,00 10.517,81 0,00';
var reg = new RegExp('SOC 01' + '\\b.*?(?:\\d\\S*\\s+){3}(\\d\\S*)', 'i');
var reg2 = new RegExp('SOC 01' + '\\b.*?(?:\\d\\S*\\s+){7}(\\d\\S*)', 'i');
var match = reg.exec(text);
var match2 = reg2.exec(text);
Output:
match[1] -> '1.667.621.57'
match2[1] -> '12.965.11'
(OBS: If you try run in the console the last number will have a comma, but in my node.js environment is a dot.)
I would like to know if i can create just one regex with two groups and sum them together.
The total should be 1.691.104,49
I was trying to sum like this:
(+match[1]) + (+match2[1])
output: NaN
Thanks.