
BillKSmith
Veteran
Nov 2, 2017, 12:33 PM
Post #3 of 4
(2925 views)
|
Re: [gaetan3009] regex integer
[In reply to]
|
Can't Post
|
|
Your script works fine for decimal integers 0 through 9 with no leading or trailing whitespace. Before you can extend it, you must decide what you mean by integer. Do you want to include a sign and/or leading zeros? Do you mean decimal integers only, or do you want to include binary, octal, hex, or even roman numerals? Do you mean normal strings or perl constants? (not an issue for decimal only). Is there a maximum number of digits? Ignore commas? The solution is simple if you wish to accept only unsigned decimal integers (including zero) of any length, preceded by any number of leading zeros, with no whitespace or commas. Change:
#if ($num =~ /^\d$/) { if ($num =~ /^\d+$/) { Good Luck, Bill
|