const regex = new RegExp('\\b([A-Z]+)0(?=\\d{3}\\b)', 'gm')
const str = `SK0498 should return SK498 (total digits = 4 = omit the single leading zero)
AA007 should still return AA007 (because the leading zeros are double, and total digits is only 3)
UA2138 returns UA2138 (no leading zeros involved)
BA023 should return BA023 (keep the zero because total number of digits is only 3), however BA0234 should return BA234 (total digits is 4 with a single leading zero that should be omitted).
AA0007`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions