regex repetition
- From: ryan.m.lists@xxxxxxxxx (Ryan Moszynski)
- Date: Wed, 12 Jul 2006 18:08:32 -0400
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
i tried using this to check to make sure they input a valid list that
i can process:
###########
foreach ($temp2 = <>) {
$list1 = $temp2;
if ($list1 =~ /(\s*\d+;)+/g || $list1 =~ /(\s*\d+;)+/g ) {
print "yay\n";
}else {print "boo\n";};
#print "...",$list1, "...\n";
}
###########
which doesn't work, because as soon as it matches the first time,
anything goes. How do i get it check for repetition, even though i
don't know how many repetitions there will be. there could be
1,2,3,5, even 10 groupings.
so the pattern isns't hard, there has to be a number, then either a
'-' or s ';', then repeat or not. the only special case is the first
one which could just be a single number, or a number '-'number. I
just don't know how to implement it.
(#(-||;))(#(-||;))(#(-||;))
thanks, ryan
.
- Follow-Ups:
- Re: regex repetition
- From: Mumia W.
- Re: regex repetition
- From: Aaron Priven
- Re: regex repetition
- From: Dr.Ruud
- Re: regex repetition
- From: John W. Krahn
- Re: regex repetition
- From: Rob Dixon
- RE: regex repetition
- From: Timothy Johnson
- Re: regex repetition
- From: Mr. Shawn H. Corey
- Re: regex repetition
- Prev by Date: RE: question on redirecting output of Perl debugger commands
- Next by Date: Re: regex repetition
- Previous by thread: Copying files in windows from one directory to the other
- Next by thread: Re: regex repetition
- Index(es):
Relevant Pages
|
Loading