javascript - Modify (bold) all words before a certain word -
i have list of near 1000 awards appear on site. each award in it's own span, , follows format
x y example:
<span>broadcast film critics association award best director</span> for each of these spans, bold text before "for". how can search unlimited possible number of words before (and not including) word(not characters) "for", , bold them?
i know expression like
\s+\s+\s+\s+for i searching 2 words before (and including) characters f, o, , r. want match word "for", , not characters, , don't want include "for" in being bolded.
regex seem best solution here, suggest using regex matches groups can rebuild string when adding <b> tags in. try this:
$('span').html(function(i, v) { var matches = /(.+)(for.+)/gi.exec(v); return '<b>' + matches[1] + '</b>' + matches[2]; });
Comments
Post a Comment