-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of $Bill Luebkert Sent: Tuesday, May 02, 2006 5:42 PM To: perl-win32-users@listserv.ActiveState.com Subject: Re: Easy One
<snip: snippiness> >> The original problem stated that the string >> will have different numbers of alphabetic characters and numbers while >> your regex specifies 4 digits exactly. > Easily remedied (I noted on it if they were exactly 4) this will handle > otherwise : > > if (/^(\D{1,4})(\d{1,4})$/) { > print "alpha='$1' num='$2'\n"; > } else { > print "Bad expr: $_\n"; > } > > The point is that it's just one if that does it all. Hmm, you still might have a problem. What if there are two letters and six numbers, or only two letters and four numbers? We can use a zero-width lookahead assertion to make sure that there are 8 characters before the end of the string, like so: ######################## use strict; use warnings; no warnings qw(uninitialized); my @str = ('AAAA1111','!!!!!!!!','ssdfs22222'); foreach my $str(@str){ print "\$str => $str\n"; if ($str =~ /^(?=.{8}$)(\D+)(\d+)$/){ print "\$1 => $1 \n\$2 => $2\n"; }else{ print "ERROR: Bad Expression!\n"; } print "\n"; } ######################### _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs