Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Regex : Limit value of a stringby AppleFritter (Vicar) |
on Oct 14, 2015 at 09:29 UTC ( [id://1144836]=note: print w/replies, xml ) | Need Help?? |
The following regex:
aside from not anchoring to the end of the string, as hippo has pointed out, explicitely attempts to match numbers from 1 to 48 only, so using this to extract said number and then checking to see whether it's greater than 48 won't work. It won't be; if it were the regex wouldn't match in the first place. As an aside, is there a reason you're explicitely capturing the backslashes and the zero? I'm assuming not; I've removed those captures below, but if you need them after all for some reason just put them back in. Now, asides aside, since you don't want to explicitely check whether the number's greater than 48, you'll just want to match the regex against the user's input, and only proceed if it does (knowing then that the number does not exceed 48). And I'd do that anyway, since if the input you're matching against is supplied by the user, the rest of it may also not be what you expect, and explicit matching will make sure you're getting precisely what you expect. So just do something like this:
In Section
Seekers of Perl Wisdom
|
|