I am trying to find similar strings in feedback option texts using regex to make them bold. Example feedback option list.
The following code works in Jquery but it only finds the first matched word so "low", "moderate" and "high" are found but then it doesn't match the word groups "low to moderate" or "moderate to high". How can I make sure it would look for each option without exiting the regex on the first found single word?
var feedBackRiskTxt = currentFeedbackNode.find('Risk[result='+choice+']').text().replace(/(\blow|low to moderate|moderate|moderate to high|high\b.)/, "<span>$1</span>");
Thank you in advance, Attila
It looks to me like you need the "g" option on your regex so it will replace all matches it finds.
Also, you aren't using the \b characters correctly if you want a word boundary on both ends of every match and the match of a trailing period wasn't working properly either. You can use this to fix those issues:
var feedBackRiskTxt = currentFeedbackNode.find('Risk[result='+choice+']').text().replace(/\b(low|low to moderate|moderate|moderate to high|high)\./g, "<span class='bold'>$1.</span>");
You can see it work here: http://jsfiddle.net/jfriend00/Y8Csf/.