I am looking for a Javascript regex for an app I am building in jQuery to do:
3 letter words to all caps: src to SRC
And any underscores to spaces: sub_1 = SUB 1
Then anything longer than 3 letters to be the first letter capitalized: offer to Offer. I get the overall idea to create the base of these, but not sure the best way to combine them all for performance any ideas?
- src to SRC
- sub_1 to SUB_1
- offer to Offer
UPDATE, this is what I have now:
$('#report-results-table thead tr th').each(function(index) {
var text = $(this).html();
// text = text.replace(/\n/gi, '<br />');
text = text.replace(/_/gi, ' ');
text = text.replace(/((^|\W)[a-z]{3})(?=\W)/gi, function (s, g) { return g.toUpperCase(); })
text = text.replace(/\w{4,255}(?=\W)/gi, function (s, g) { return s.charAt(0).toUpperCase() + s.slice(1); })
$(this).html(text);
});
Thanks
This works for me…
For your specific use case…