contenteditable div内の一連の単語のすべての一致を見つける次のJavascript関数があります:
var words = ['oele', 'geel', 'politie', 'foo bar'];
function markWords() {
var html = div.html().replace(/<\/?strong>/gi, ''),
text = html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' '),
exp;
$.each(words, function(i, word) {
exp = new RegExp('\\b(' + word + ')\\b', 'gi');
html = html.replace(exp, function(m) {
console.log('WORD MATCH:', m);
return '<strong>' + m + '</strong>';
});
});
//html = html.replace(' ', ' ').replace(/\s+/g, ' ');
div.html(html);
}
アットマークで始まる場合にのみ、これらすべての単語をマークするように変更するにはどうすればよい@
ですか? たとえば@foo bar
、 などと一致する必要があります。