Let us change our traditional attitude to the construction of programs. Instead of imagining that our main task is to instruct a computer what to to, let us concentrate rather on explaining to human beings what we want a computer to do.
Nicely done, but #119 is in error as of this writing. It matches a single digit, or two digits, or a one or two followed by two digits under six. That means it won't match its own one-liner number! Or any other useful numbers like 192 and 168 and 127, which come up a lot in IP addresses.
I believe a correct regexp would be:
/^1?\d{1,2}|2[0-4]\d|25[0-5]$/
That matches:
- any one or two digits, optionally starting with "1", so that's 0-9, 00-99, and also 100-199 and (redundantly but harmlessly) 10-19 again
- 200 to 249
- 250 to 255
I haven't run a test, but I'm reasonably confident that it's right.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Education Sponsors
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
Nicely done, but #119 is in error as of this writing. It matches a single digit, or two digits, or a one or two followed by two digits under six. That means it won't match its own one-liner number! Or any other useful numbers like 192 and 168 and 127, which come up a lot in IP addresses.
I believe a correct regexp would be:
/^1?\d{1,2}|2[0-4]\d|25[0-5]$/
That matches:
- any one or two digits, optionally starting with "1", so that's 0-9, 00-99, and also 100-199 and (redundantly but harmlessly) 10-19 again
- 200 to 249
- 250 to 255
I haven't run a test, but I'm reasonably confident that it's right.
Comment Responses
Yours is correct:
$ perl -E 'for (0..255) { $count+=m/^1?\d{1,2}|2[0-4]\d|25[0-5]$/}END{say$count}' 256Reply To This Comment