With below code I'm attempting add a style to a string using regex, but instead of
'updated' being set to <'span style='color:blue' >test</span> text'
its being set as 'test text'. Am I misusing regex ?
src :
var text = 'test text';
var stringToStyle = 'test';
var update = "<span style='color:blue' >" + stringToStyle + "</span>";
var updated = text.replace('/'+stringToStyle+'/gi' , update);
console.log(update);
console.log(updated);
plunkr : https://plnkr.co/edit/6uO3M8kATQLXvWWVx1Vw?p=preview
var updated = text.replace(RegExp(stringToStyle, "gi") , update);