WC -Sx- Jones <[EMAIL PROTECTED]> wrote:
: 
: PCRE 4.5 revisited  :(

    What's PCRE 4.5?

 
: I am trying to reduce this into something "smaller/shorter" -
:
/213\.37\.(?:(?:(?:1(?:[5-9][0-9])|(?:2(?:0|1|2|3|4)[0-9])|(?:25[0-1]))))\.\
d{1,3}/

Let's break it down:

/
    213\.
    37\.
    (?:
        (?:
            (?:1        # 150 - 199, 1200 - 1251 ???
            
                (?:                 # 50 - 99
                    [5-9]
                    [0-9]
                )
                |
                (?:2                # 200 - 249
                    (?:0|1|2|3|4)
                    [0-9]
                )
                |
                (?:25[0-1])         # 250 - 251
            )
        )
    )
    \.
    \d{1,3}
/x

    I assume you wanted the 150 - 251 range.
Here's the test:

foreach ( 149, 150, 160, 240, 255, ) {
    if ( /
            (?:                 # 150 - 199
                1
                [5-9]
                [0-9]
            )
            |
            (?:                 # 200 - 249
                2
                [0-4]
                [0-9]
            )
            |
            (?:                 # 250 - 251
                2
                5
                [0-1]
            )
        /x ) {

        print "in range\n";

    } else {
        print "out of range\n";
    }
}
__END__
I get:
out of range
in range
in range
in range
out of range


    Now we'll ungroup the non-grouping groupings:   :)

foreach ( 149, 150, 160, 240, 255, ) {

    if ( /
            1                # 150 - 199
            [5-9]
            [0-9]

            |

            2                # 200 - 249
            [0-4]
            [0-9]

            |

            2                # 250 - 251
            5
            [0-1]
          /x ) {

        print "in range\n";

    } else {
        print "out of range\n";
    }
}
__END__
I get:
out of range
in range
in range
in range
out of range


    Now we test it without the spacing:

foreach ( 149, 150, 160, 240, 255, ) {

    if ( /1[5-9][0-9]|2[0-4][0-9]|25[0-1]/ ) {

        print "in range\n";

    } else {
        print "out of range\n";
    }
}
__END__
I get:
out of range
in range
in range
in range
out of range


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to