Skip to content

Instantly share code, notes, and snippets.

@X-Raym
Created April 26, 2022 07:31
Show Gist options
  • Save X-Raym/38d46c401a22514644278c2a28d4f03d to your computer and use it in GitHub Desktop.
Save X-Raym/38d46c401a22514644278c2a28d4f03d to your computer and use it in GitHub Desktop.
// From: http://jsfiddle.net/L6LB2/1/
var str = "AddMediaItemTrack";
var words = ["Add", "Track", "Ma"]
var mapObj = {}
for( word of words ) {
mapObj[word] = "<mark>" + word + "</mark>"
}
var re = new RegExp(Object.keys(mapObj).join("|"),"gi");
str = str.replace(re, function(matched){
return mapObj[matched];
});
console.log(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment