Forum Discussion
_anomDiebolt_
10 years agoQrew Elite
I don't think this is a good idea to actually implement this in the formula language - but it is technically possible to do by manually splitting apart the text field first on commas and then on spaces using Right(), Left() NotRight(), and NotLeft(). You will have to assume a maximum number of numeric values embedded in your text string and write the formula to parse out that many numbers and multiply them together. But I would suspect some user is going to deviate from the assumed format over time and the formula will eventually fail.
On the other hand this can done using script in a reliable way. This code fragment splits the text field on non-digits using a regular expression and then reduces the array by multiplying all non-empty terms together.
var field = "1 Pair per Bag, 12 Bags per Inner Bag, 12 Inner Bags per Case";
var terms = field.split(/\D+/g);
var product = _.reduce(terms, function(memo, item) {
return item.length > 0 ? item * memo : memo;
}, 1);
console.log(product);
logs 144
On the other hand this can done using script in a reliable way. This code fragment splits the text field on non-digits using a regular expression and then reduces the array by multiplying all non-empty terms together.
var field = "1 Pair per Bag, 12 Bags per Inner Bag, 12 Inner Bags per Case";
var terms = field.split(/\D+/g);
var product = _.reduce(terms, function(memo, item) {
return item.length > 0 ? item * memo : memo;
}, 1);
console.log(product);
logs 144