Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: IP Filtering RegEx needed

by Roger (Parson)
on Sep 15, 2004 at 14:22 UTC ( [id://391182]=note: print w/replies, xml ) Need Help??


in reply to IP Filtering RegEx needed

You need to quote the meta characters in the regex with \Q and \E. Otherwise you need to escape the meta-characters (such as [ and .) with backslash (\).

Here's an example:
#!/usr/bin/perl -w use strict; my $grp = qr/\[\d+-\d+\]/; for (<DATA>) { print if /\d+\.\d+\.$grp\.(\d+|$grp)/; } __DATA__ 123.145.[146-149].2 135.168.[10-115].[0-125] 135.168.12.[0-125]


Update:
Sorry I misread the question. If you are after a single regex to do range checking, you can use the match time interpolation technique.
#!/usr/bin/perl -w use strict; my $grp = qr/^123\.145\.(\d+)\.(\d+)$(??{ $1 >= 146 && $1 <= 148 ? '' +: 1})/; for (<DATA>) { print if /$grp/; } __DATA__ 123.145.130.3 123.145.146.3 123.145.147.3 123.145.148.3 123.145.149.3

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://391182]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found