in reply to regular expression to match numbers
I'm not sure why you'd want to write a regular expression for this, unless it was homework :) If you insist, something like this would do the trick:if ($x >= 1 && $x <= 10) { print "Correct match"; } else { print "Incorrect"; }
This uses ^ and $ to anchor the expression to the whole string and the brackets to restrict the alternation. See perlre for more help.if ($x =~ /^([1-9]|10)$/) { # etc }
gav^
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: regular expression
by Anonymous Monk on Jun 08, 2002 at 03:35 UTC |