On 30/11/2010 06:39, Uri Guttman wrote:
"GK" == Guruprasad Kulkarni<[email protected]>  writes:

   GK>  Here is another way to do it:

   GK>  /^127\.0\.0\.([\d]|[1-9][\d]|[1][\d][\d]|[2]([0-4][\d]|[5][0-4]))$/) {

why are you putting single chars inside a char class? [\d] is the same
as \d and [1] is just 1.

Also this is another solution that wrongly verifies 127.0.0.0. It also unnecessarily makes use of captures instead of grouping, and puts single values into character classes ([1], [\d] etc.). Perhaps it is better written:

  /^127\.0\.0\.(?:
    [1-9]\d? | # 1 .. 99
    1\d\d    | # 100 .. 199
    2[0-4]\d | # 200 .. 249
    25[0-4]    # 250 .. 254
  )$/x;

But my feeling is that these long-winded pure regex solutions are more of a response to a challenge than a practical solution. At the very least they need commenting to explain what they are doing. Capturing the value of the last byte field, as I suggested, seems to describe the purpose of the code far better, with no significant penalty that I can think of.

- Rob

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to