Javascript Find Names In Strings
What's a good JavaScript library for searching a given string for a large list of names. For example, given a list of 1000 politicians names find every instance in a string and wra
Solution 1:
var names = ['foo','bar'];
var content = "this foo is bar foobar foo ";
for (var c=0,l=names.length;c<l;c++) {
var r = new RegExp("\\b("+names[c]+")\\b","gi");
content = content.replace(r,'<span class="mp">$1</span>');
}
Post a Comment for "Javascript Find Names In Strings"