in reply to positive integer identification (regular expression question)
Do want to see if it is an integer or if it's a string that looks like an integer?
Since you've anchored the regex at the begging and at the end I'm going to assume that you're checking that the value is a positive integer.
Check if the value is a Positive Integer:if ( $ref == int($ref) and $ref eq int($ref) and $ref > 0 ) { print "$ref is a positive int!\n" }
I'll leave the negative test as an exercise for the reader.
update: added an additional test to prevent strings like 23EatAtJoes being considered a positive integer.
This method fails and is unwieldy with integers larger than 999999999999999 on my system. I suggest Using one of the more robust methods suggested in the thread.
--
|
|---|