Why not just use split()?  Then you can do a simple regex on each
element:

#######################

use strict;
use warnings;

my $string = '1-10;25;33;1-00-250';

my @array = split(/;/,$string);
foreach my $element(@array){
   if($element =~ /^\d+-?\d*?$/){
      print "$element => valid\n";
   }else{
        print "$element => bad input\n";
   }
}

########################

Of course you could also skip the intermediary array and just do

   foreach my $element(split(/;/,$string)){

I just added it for clarity.






-----Original Message-----
From: Ryan Moszynski [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 12, 2006 3:09 PM
To: beginners
Subject: regex repetition

I need to write some code to allow users to specify which of a whole
bunch of elements(e.g.512/1024) that they want to view.  My idea for
how to do this was to have them input a semicolon delimited list, for
example:

1-10;25;33;100-250


Snip>

        if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) {

<snip>



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to