var iCounter = 0, oMatch = null ; sSubject = Utils.trim(sSubject.replace(/[\s]+/, ' ')); do { oMatch = /^Re(\[([\d]+)\]|):[\s]{0,3}Re(\[([\d]+)\]|):/ig.exec(sSubject); if (!oMatch || Utils.isUnd(oMatch[0])) { oMatch = null; } if (oMatch) { iCounter = 0; iCounter += Utils.isUnd(oMatch[2]) ? 1 : 0 + Utils.pInt(oMatch[2]); iCounter += Utils.isUnd(oMatch[4]) ? 1 : 0 + Utils.pInt(oMatch[4]); sSubject = sSubject.replace(/^Re(\[[\d]+\]|):[\s]{0,3}Re(\[[\d]+\]|):/gi, 'Re' + (0 < iCounter ? '[' + iCounter + ']' : '') + ':'); } } while (oMatch); sSubject = sSubject.replace(/[\s]+/, ' '); return sSubject;