in reply to REGEX Match Single Digit
If you know your digit ahead of time, there's not need to worry about character classes. You can just use:
/^1$/
if you are committed to using a regular expression. If you don't know until runtime, you can use
/^$value$/
where you have stored your value in the variable $value. You need to remember that regular expressions are just a fancy string matching engine, so don't think about numbers as numbers, but as characters.
However since you are not really performing flexible matches at this point but are checking equality, you should be using Equality Operators. For a string comparison, eq is the correct choice, but since you are checking numbers, you should use
if ($_ == 1) { # Do stuff }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: REGEX Match Single Digit
by spickles (Scribe) on Aug 28, 2009 at 16:00 UTC | |
by ikegami (Patriarch) on Aug 28, 2009 at 16:11 UTC | |
by kennethk (Abbot) on Aug 28, 2009 at 16:21 UTC |