For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2008 > how to write 0 to 10 in reg exp.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to write 0 to 10 in reg exp.
itshardtogetone@hotmail.com

2008-04-02, 4:30 am

Hi,
How do I write the expression, if the variable match between 0 to 10? Below is the wrong expression I wrote which is suppose to be if $eightdecks match 0 to 10. So i want the answer to be yes.
Thanks

my $eightdecks = 6;

if($eightdecks =~ /[0-10]/){
print "Yes match\n";
}else{print "no"};
Jeff Pang

2008-04-02, 4:30 am

try this one:

# perl -Mstrict -le 'my $x=shift; print 1 if $x=~/^[0-9]$|^10$/' 10
1



On 4/2/08, itshardtogetone@hotmail.com <itshardtogetone@hotmail.com> wrote:
> Hi,
> How do I write the expression, if the variable match between 0 to 10? Below is the wrong expression I wrote which is suppose to be if $eightdecks match 0 to 10. So i want the answer to be yes.
> Thanks
>
> my $eightdecks = 6;
>
> if($eightdecks =~ /[0-10]/){
> print "Yes match\n";
> }else{print "no"};

Sanket Vaidya

2008-04-02, 8:08 am

Here is the code to match 0 to 10 using regex.


use warnings;
use strict;

print "Enter any number:";
my $input = <STDIN>;
chomp($input);

if($input=~ m/^10$|^[0-9]$/)
{
print "matched";
}
else
{
print "not matched";
}


Hope it helps.


-----Original Message-----
From: itshardtogetone@hotmail.com [mailto:itshardtogetone@hotmail.com]
Sent: Wednesday, April 02, 2008 2:09 PM
To: beginners@perl.org
Subject: how to write 0 to 10 in reg exp.

Hi,
How do I write the expression, if the variable match between 0 to 10? Below
is the wrong expression I wrote which is suppose to be if $eightdecks match
0 to 10. So i want the answer to be yes.
Thanks

my $eightdecks = 6;

if($eightdecks =~ /[0-10]/){
print "Yes match\n";
}else{print "no"};

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com