I have a string variable where I have a text that needs to be replaced. This text appears several times.
For example:
let title="Hello [username], your name is [username]. Goodbye [username]"
and
myuser = "Danielle"
the following line does does the trick:
title = title.replace(/username/gi, myuser)
And this is the result I get:
Hello [Danielle], your name is [Danielle]. Goodbye [Danielle]
But what I really want to replace is [username], like this:
title = title.replace(/[username]/gi, myuser)
Which does not work.
I tried [username], "[username]", '[username]'... etc but nothing seems to work.
What am I doing wrong?
Thanks.