Daniel Stellwagen wrote:
>
> Hi everybody,
Hello,
> I am a beginner of programming ( so I am a beginner of perl programming
> too :-) ) and I have this very basic problem but cannot handle it.
>
> I'm trying to match only a one single digit and wrote this code:
>
> use strict;
>
> my $number = 11; # two-digit number
>
> if ( $number =~ /\d{1}\b/ ) {
> print "Match\n";
> } else {
> print "No Match\n";
> }
>
> But I get a match !?
> I also tried:
>
> $number =~ /\d?\b/
> because ? stands for no or one character
>
> But that didn't work either.
>
> Can someone give me a hint and maybe a source for more
> basic dokumentation about reg exp.
Your regular expression has a word boundary (\b) anchor after a single
digit character class (\d). That will match the digit '7' in the
following examples: ' 567 ', '567*&^%', '567', etc. You have to
anchor both sides of the expression you want to match:
if ( $number =~ /\b\d\b/ ) {
Or more probably:
if ( $number =~ /\A\d\z/ ) {
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>