$(".post .body").each(function( ) { var isMatch = /^(@XPLANE|@XP)+/.test($.trim($(this).text())); if(isMatch) { $(this).css("background-color", "antiquewhite"); } });