Im trying to target the first word of each line to change the color to only the first word on it. Right now this is being populated by a textarea on the backend.
textarea
split on breaks (or newlines ?), and add a span around the first word with a word mathcing regex :
$('.items').html(function(_,html) { var lines = html.split(//gi); for (var i=lines.length; i--;) { lines[i] = $.trim(lines[i]).replace(/^(\w+)/, '$1') } return lines.join(''); });
FIDDLE