I have function to bold part of line before colon.
//Fast regex (time: 0) var colonRegex = /^[^*:\n]+:/gm; and
//Slow regex (time: 139) Limit by 10 words //var colonRegex = /^([^*:\n ]+ ?){1,10}:/gm; // I have issue with it when I want to apply replace to tens of divs (it freezes chrome) var bolded = str.replace(colonRegex, function(match) { return "<b>"+match+"</b>"; }); you can test it on jsfiddle: http://jsfiddle.net/damg7zuk/4/
Where I do a mistake? I can make word limitation inside the callback. Can it be done better in regex itself? Thank you for your trick.
.replace(colonRegex,"<b>$1</b>");? (If you add some parentheses to the regex:/^([^*:\n]+:)/gm.) If I add the slow regex to your fiddle it runs in "Time: 34" and doesn't freeze Chrome.