One solution could look like this:
Be careful with the regex, since I
const test = "a:1|b:2,3|c:4,5";
const regex = /(\w):([\d,]+)/gm;
const matches = test.matchAll(regex);
const prod = [];
const product = {};
for (const [_, key, value] of matches) {
const numbers = value.split(",").map((n) => parseInt(n));
product[key] = numbers;
}
const variableName = Object.keys({ test })[0]; // https://stackoverflow.com/a/52598270/8211893
prod.push({
name: variableName,
product
});
console.log(prod);
am ignoring the pipe character. Also I am only checking for one character before the semicolon, so you might want to adjust that expression.