Let's remember to anchor the location of the string...

$serial = "455WD165";
if ($serial !~ m/^[0-9]{3}[A-Z]{2}[0-9]{3}$/ ) {
   print "Bad!";
} else {
  print "Good!";
}

The caret and dollar sign are very important. Without it, someone could type
HK45J455WD165AGKB and it would still pass the reg exp because the proper
formatted serial number is embedded somewhere in that string. With the ^ and
$, it will only pass if these are the only characters in a string.

Best Regards,
JOSHUA D. HAYDEN

----- Original Message -----
From: "Tim Doty" <[EMAIL PROTECTED]>
To: "Kamali Muthukrishnan" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, April 26, 2002 9:48 AM
Subject: RE: pattern matching for serial number


> well, the second slash should follow immediately after the bracket (in
> present case it adds another character to the reg-ex. If you can cut &
paste
> the code segment it would avoid typographical errors. When I use the
> following it performs as expected w/o syntax error.
>
> #!/usr/bin/perl
>
> $serial = "4595WAD165";
>
> if ($serial !~ m/[0-9]{3}[A-Z]{2}[0-9]{3}/ ) {
>   print "alert\n";
>   }
>
> else {
>   print "check\n";
>   }
>
> > -----Original Message-----
> > From: Kamali Muthukrishnan [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, April 26, 2002 10:17 AM
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: Re: pattern matching for serial number
> >
> >
> > Sorry, while typing I missed the slash, it is there in my code as -
> >   if ($serial !~ m/[0-9]{3}[A-Z]{2}[0-9]{3} /)
> > Is there any thing wrong with this ?
> > Kamali
> > >>> fliptop <[EMAIL PROTECTED]> 04/26/02 08:54AM >>>
> > Kamali Muthukrishnan wrote:
> >
> > > Hi guys :
> > > I have serial numbers with a pattern : 3 numbers followed by 2
> > capital letters followed by 3 numbers.
> > > To validate this -
> > >   if ($serial !~ m/[0-9]{3}[A-Z]{2}[0-9]{3} )
> > >       {  # display error ;  }
> > > I get a syntax error.
> >
> >
> > i think you're missing a closing slash (/) in your regex.  the format is
> >
> > if $something =~ m/regex_here/
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to