I have a string in JavaScript in which I\'d like to find all matches of a given phrase and wrap them with a tag. I haven\'t been able to find the right regex method here to
You can do straight-up replace by using a replace function:
str.replace(/cat/ig, function replace(match) { return '' + match + ''; });