What you’re trying to do is to convert each digit to base 10. As each digit is from the range 0, 1, …, 8, 9, A, B, …, Y, Z, you’re dealing with a base-36 string. Therefore, parseInt
can be used:
const convertBase36DigitsToBase10 = (input) => Array.from(input, (digit) => {
const convertedDigit = parseInt(digit, 36);
return (isNaN(convertedDigit)
? digit
: String(convertedDigit));
}).join("");
console.log(convertBase36DigitsToBase10("158A52C3")); // "1581052123"
console.log(convertBase36DigitsToBase10("Hello, world!")); // "1714212124, 3224272113!"
If you really want to stick to regex, the answer by xdhmoore is a good starting point, although there’s no need for “regex dogmatism”.