Say I have a string "abc123def45"
Is it possible, with javascript regex to replace all the numbers in the string to be either the same length or all at a fixed length of, say, 6 digits.
So, if going for the 6 digits approach, the resulting string would be "abc000123def000045"
And if going for the same length approach (which I suspect will be harder if not impossible with regex), the resulting string would be "abc123def045"
I can certainly find all the numbers with regex with something like:
\d+
but how do I get the right amount of leading zeros in the replacement?
Sample code:
var s = "abc123def45";
var r = s.replace(/\d+/g, "000123"); // this is wrong of course