# Standardise leading zeroes in an input string

Write a program in the shortest number of bytes possible that will parse any string given to it by input, and output that string with any and all numbers padded with leading zeroes to match the largest number's length.

For example:

Input:

This 104 is an -8 example of 4.518 a string 50.


The generated output should become:

This 104 is an -008 example of 004.518 a string 050.


Note that any digits after the period are not considered part of the "length" of a number. Numbers are considered any sequence of digits with either 0 or 1 periods in the sequence. Numbers will be delimited with either the string boundary, spaces, commas, or newlines. They can also be followed by a period, but only if the period is then followed by a delimiting character. They can also be preceded with a '-' to indicated negatives. So something like this:

The strings 20.d, 5.3ft and &450^ are not numbers, but 450.2 is.


Should output the following:

The strings 20.d, 5.3ft and &450^ are not numbers, but 450.2 is.


That is to say, no modifications.

String input will be no more than 200 characters, if your program has an upper bound for some reason.

The winning answer will be the answer in the shortest number of bytes in seven days from the posting of this question.

### Test cases

Input:

2 40 2


Output:

02 40 02


Explanation: both substrings 2 are bounded on one side by a string boundary and on the other side by  .

Input:

E.g. 2,2.,2.2,.2,.2., 2 2. 2.2 .2 .2. 2d 2.d 2.2d .2d .2.d 40


Output:

E.g. 02,02.,02.2,00.2,00.2., 02 02. 02.2 00.2 00.2. 2d 2.d 2.2d .2d .2.d 40


Explanation: in the first two groups the first four numbers are followed by a delimiter (, or  ) and the final one is followed by a period then a delimiter; in the third group, each sequence is followed by the non-delimiter d.

• @MartinBüttner yeah, that's a bit confusing, but basically it means that in "253.47", " 253" isn't a number even though it's followed by a period - it's part of a number. Will reword it when I'm back home. – Sellyme Aug 19 '14 at 7:58
• @JanDvorak I feel like doing so would kind of defeat the point of the challenge - that's an exercise left to the reader. Happy to provide more examples and clarification though. – Sellyme Aug 19 '14 at 7:59
• so, there's no number in 257.24ft? Now that's interesting... – John Dvorak Aug 19 '14 at 8:00
• @SebastianLamerichs note that 253.47 is not a sequence of digits... – John Dvorak Aug 19 '14 at 8:03
• @MartinBüttner I padded "4.518", not "4". Functionally they're the same. Basically, don't treat "4.518" as two separate numbers, despite them being delimited by a period. – Sellyme Aug 19 '14 at 8:04

## Ruby, 111 bytes

I hope this catches all the details of the spec

puts $*[0].gsub(r=/(?<![^,\s])(-?)(\d+)(?=\.?\d*(?![^,\s]))/){$1+$2.rjust(i.scan(r).map{|m|m[1].size}.max,'0')}  It reads the input as the first command line argument and prints the result to STDOUT. # Cobra - 282 class P def main r,s,l,n=RegularExpressions.Regex(r'^[\n,]?-?(\d+).?\d*[\n,]?$'),Console.readLine.split(' '),0,0
for m in 2,for y,x in s.numbered,if r.isMatch(x),while (n-=n-r.match(x).groups[1].length)<if(n>l,l-=l-n,l),x=s[y]=if(x[0]=='-','-0'+x[1:],'0'+x)
print s.join(' ')


For those of you wishing to test this without installing Cobra, it's rather easily converted into equivalent C# code.

## JavaScript, 201 chars

s=prompt();j=k=l=0,t={}
for(i in s){s[i]==+s[i]&&s[i]!=" "?j++:(t[i-j]=j,j=0);if(j>k)k=j;}if(j!=0)t[+i+1-j]=j