in reply to Comma-fy floats with (+/-)look(aheads/behinds)

You could do just this...
while (<DATA>) { /\./ ? s/(?<=\d)(?=(\d{3})+(?:\.))/,/g : s/(?<=\d)(?=(\d{3})+(?!\d))/,/g; print "$_"; } __DATA__ 123 1234 12345 123446 1234567 +12345678.12 -123456789.12345678
Which will give the following result:
123 1,234 12,345 123,446 1,234,567 +12,345,678.12 -123,456,789.12345678
Which is exactly what you wanted.

Replies are listed 'Best First'.
Re: Re: Comma-fy floats with (+/-)look(aheads/behinds)
by Anonymous Monk on Sep 22, 2003 at 13:24 UTC
    Thanks Roger. This was the answer I was looking for. I was trying (\.|(?!\d)) and I knew why it wasn't working. I couldn't think of a solution that only used look(aheads|behinds).

    All the answers were great. Thanks again.