With this script
getFormattedTime = function (fourDigitTime){
var hours24 = parseInt(fourDigitTime.substring(0,2));
var hours = ((hours24 + 11) % 12) + 1;
va
You can use word boundaries in your regular expression to match 4 digits, and then your getFormattedTime function as a replacement function to .replace:
$('body').html(function(_, old) {
return old.replace(/\b\d{4}\b/g, getFormattedTime);
});
Please notice also the comments by @Doorknob and @Pointy. To replace only time "numbers", you will need to markup them semantically, for example with html5
Class starts at , please be there by and sign in by .
$('time').text(function(_, old) {
return getFormattedTime(old);
});