Created
April 26, 2022 07:31
-
-
Save X-Raym/38d46c401a22514644278c2a28d4f03d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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