Using jQuery string replacements to make labels bold Instead of having multiple statements like the following, Is it possible to club them into one liner in jQuery?

       var replaced = $("#myContents").html().replace(/Employee:/g,'&lt;b&gt;Employee:&lt;/b&gt;');
       $("#myContents").html(replaced);

       var replaced = $("#myContents").html().replace(/SSN:/g,'&lt;b&gt;SSN:&lt;/b&gt;');
       $("#myContents").html(replaced);

       var replaced = $("#myContents").html().replace(/DOB:/g,'&lt;b&gt;DOB:&lt;/b&gt;');
       $("#myContents").html(replaced);


       var replaced = $("#myContents").html().replace(/Start Date\/Time:/g,'&lt;b&gt;Start Date\/Time:&lt;/b&gt;');
       $("#myContents").html(replaced);

       var replaced = $("#myContents").html().replace(/End Date\/Time:/g,'&lt;b&gt;End Date\/Time:&lt;/b&gt;');
       $("#myContents").html(replaced);
I think yes, the ugliest I think is the follow:

// Define one regexp with all the piece you need and save
// the match with ()
var re = /(Employee|SSN|DOB|Start Date\/Time|End Date\/Time):/g

// Then change the replace as follow
var replaced = $("#myContents").html().replace(re, '&lt;b&gt;$1:&lt;/b&gt;');

$("#myContents").html(replaced);


Of course you can compose your regexp as chunks as follow:

var terms = [];

...
terms.push("Employee");
...
terms.push("End Date\/Time");

...

var re = new RegExp("("+terms.join("|")+"):", 'g');

...