Re: perlfaq5: How can I output my numbers with commas added?
[email protected] ("Keith C. Ivey")
| Newsgroups | perl.perlfaq.workers |
|---|---|
| Message-ID | <3E19E680.22869.394CF584@localhost> |
pizza <[email protected]> wrote: > this is the shortest regex i can come up with that seems to work > all in one line. > > s/([+-])?(\d{1,3})(?=(\d{3})+)/$1$2,/g; I think you're missing a '$': s/([+-])?(\d{1,3})(?=(\d{3})+$)/$1$2,/g; Your version doesn't work for numbers with more than 6 digits unless the number of digits is divisible by 3 (or unless the first comma is already there). -- Keith C. Ivey <[email protected]> Washington, DC