in reply to Regexp to extract groups of numbers

#!/usr/bin/perl
###########################################
use warnings;
use strict;

my $test = "000000000000022102840002210284" ;
print "bad 30 digit number!\n\n" unless $test =~ /^\d{30}$/ ;
$test =~ /^(\d{10})(\d{10})(\d{10})/ ;
print "1 = $1\n2 = $2\n3 = $3\n";
  • Comment on Re: Regexp to extract groups of numbers

Replies are listed 'Best First'.
Re^2: Regexp to extract groups of numbers
by meredith (Friar) on Feb 09, 2005 at 03:21 UTC
    The 30-digit test you run is implied if you simply check the results of your capturing regex:
    #!/usr/bin/perl ########################################### use warnings; use strict; my $test = "000000000000022102840002210284"; if ( $test =~ /^(\d{10})(\d{10})(\d{10})$/ ){ print "1 = $1\n2 = $2\n3 = $3\n"; } else { print STDERR "Bad 30-digit number!$/"; }
    Of course, there are tons of ways to handle this problem. =)
    mhoward - at - hattmoward.org