javascript - Find all words that start with @ sign -


i have following javascript function finds matches of set of words inside contenteditable div:

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('&nbsp;', ' ').replace(/\s+/g, ' ');     div.html(html); } 

how can modify marks words, in cases start @ sign @? example, should match @foo bar, etc.

live fiddle

if change

exp = new regexp('\\b(' + word + ')\\b', 'gi'); 

to

exp = new regexp('@\\b(' + word + ')\\b', 'gi'); 

it match contents @politie or @foo bar.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -