for some translations need, I need to replace a string having three brackets like
hello {{{'something'}}} world {{{'something else'}}} ...
with a string containing two brackets and the values
{
value: "hello {{1}} world {{2}}...",
params: {1: 'something', 2: 'something else', ...}
}
I started with this codepen :
let brutto = "hello {{{'something'}}}} world {{{'something else'}}} ... ";
let regex = /[{]{3}(.+?)[}]{3}/;
let netto = brutto.replace(regex, "{{1}}");
let paramArray = brutto.match(regex).map((e, i) => {return {i: e}});
let result = { value: netto, params: paramArray }
console.log(result);
I get
{
"value": "hello {{1}}} world {{{'something else'}}} ... ",
"params": [
{
"i": "{{{'something'}}}"
},
{
"i": "'something'"
}
]
}
that is not really close to the desired result...