I am trying to replace a particular string using regex.
var replace = {'<RAndom>': "random object"};
I am replacing it using the dynamic regex because i have a lot of objects.
var tagsText = "<RAndom> hellow world";
var regex = new RegExp('\\b(' + Object.keys(replace).join('|') + ')\\b', 'g');
tagsText = tagsText.replace(regex, function(match) {
return replace[match] + match;
});
But it is not working.I think the problem is with the semicolon but i am not sure.The output is again the same.
"<RAndom> hellow world"
Any ideas?
\\bs or replace with(^|\\W)and(\\W|$)respecitively.