I am getting a sometimes random string that will always contain [] with special string inside of it. I would like to use the text inside each bracket and use it in a function to replace the text inside each bracket. Here is an example: So far I have
let string = 'test [a] test2 [b]'
let test = string.replace(/\[(.+?)\]/g, ""+getValue(text inside bracket replaced here)+"")
function getValue(text) {
//this function will return a value based on the certain text it receives
}
console.log(test)
'test [replaced text based on a value] test2 [replaced text based on b value]'
Thanks for the help in advance.