On Oct 13, [EMAIL PROTECTED] said:
my $match = '1ak';
if ($match =~/([a-hj-nprt-wyA-HJ-NPRT-WY])/ ){
But when I am executing its still giving me Ok as output .The Problem is
like this I want to match only character (a-h,j-n,p,r,t-w,y) including
upper case also or in other words I need Error when it it encounters with
any letter [IOQSXZ].
I know we can do with /[^IOQSXZ]i/. But the thing is I want to check only
alphabets(except those which I just mentioned) or hypen(-) can be pass
through this test.
The problem is your regex is just saying "does $match have one of these
characters in it?", where you want to say "make sure $match ONLY has these
characters in it".
For that, you'd do:
if ($match =~ /^[a-hj-nprt-wyA-HJ-NPRT-WY]{3}\z/) {
# $match is made up of three of those characters
}
The \z anchor is like the $ anchor, which mean "end of string", except
that $ can allow for a newline at the end of the string, whereas \z does
not. Perhaps, though, it's overkill, since you're already making sure
$match only has 3 characters.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://www.perlmonks.org/ % have long ago been overpaid?
http://princeton.pm.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>