I would like to replace a string in another string. My problem is, that the search-string is a variable and I need to set a group for this, because I want to reuse the original matching string.
const string = 'Any string with many words'
const label = 'any'
const re = new RegExp(label, 'gi')
string = string.replace(
re,
'>>>' + $1 + '<<<'
)
console.log(string)
// Expect: >>>Any<<< string with m>>>any<<< words