<script> for (var n = 0; 100 > n; n++) document.write(n + " -> " + ("" + n).replace(/\d*(2|3)\d*/, function(b, a) { return { 2: "xxx", 3: "yyy" }[a] }) + "<br>"); </script>