I current have the following code:
const pattern = "quick";
const re = new RegExp(pattern, "gi");
const string = "The quick brown fox jumped over the lazy QUICK dog";
const replaced = string.replace(pattern, "<b>" + pattern + "</b>");
console.log(replaced);
It produces the following:
The <b>quick</b> brown fox jumped over the lazy QUICK dog
What I want is:
The <b>quick</b> brown fox jumped over the lazy <b>QUICK</b> dog
I'm having two issues.
Firstly, why isn't QUICK being replaced when I'm using a case insensitive regex?
Secondly, how do I ensure that QUICK is replaced with <b>QUICK</b> and not <b>quick</b>?
re... and never use it ... so that's something you should look at - tryconst replaced = string.replace(re, "<b>" + pattern + "</b>");