The following is off the cuff, but it might work for you. Note that it also allows for negative numbers. Unlike Popcorn Dave's solution, I combine the test and the number extraction into one step. You may or may not like this. (and I just cleaned up the code)
#!/usr/bin/perl -l use strict; use warnings; my @numbers = ( 23, '1,234', '2,2', '12,234,567', -1, '-12,234', '-23,23', '999,999', 0 ); foreach my $number (@numbers) { if (my @sections = $number =~ /^(-?\d{1,3})(?:,(\d\d\d))*$/) { print join '', grep {defined} @sections; } else { # not a valid number } }
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
In reply to Re: Re: Re: Match number with commas
by Ovid
in thread Match number with commas
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |