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(' ', ' ').replace(/\s+/g, ' '); div.html(html); } how can modify marks words, in cases start @ sign @? example, should match @foo bar, etc.
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
Post a Comment