Link to home
Start Free TrialLog in
Avatar of Electrotec
Electrotec

asked on

Problem with Regular Expression

Hi,
I didn't know where to ask about this, but here seemed a popular place for Regular Expressions!

I am using NetTracker in order to sort the ip addresses of my visitors into Hosts.  To do this, I need to use regular expressions.  

I need to get all addresses (fictional addresses used here) from 200.100.129.1 to 200.100.129.127 in one host group and 200.100.129.128 to 200.100.129.255 in another host group.  I have the following regular expression for the first host group:

200.100.129.(\d|[123456789]\d|11[0123456789]|12[01234567])

Unfortunately, this picks up for both host groups - 200.100.129.1 upto 200.100.129.255.  Where am I going wrong?

Thanks.
Avatar of manav_mathur
manav_mathur

for group2

/200\.100\.129\.(1(?=(2(?=[8-9])|[3-9](?=\d)))|2(?=[0-5]))\d/
Here's a sample that I got

use strict ;
use warnings ;
while(<DATA>) {
print if /200\.100\.129\.(1(?=(2(?=[8-9])|[3-9](?=\d)))|2(?=[0-5]))\d/ ;
}
__DATA__
200.100.129.255
200.100.129.126
200.100.129.127
200.100.129.128
200.100.129.129
200.100.129.130
200.100.129.131
200.100.129.12
200.100.129.174
200.100.129.110


output
200.100.129.255
200.100.129.128
200.100.129.129
200.100.129.130
200.100.129.131
200.100.129.174

 for group1

/200\.100\.129\.(1|1[0-9]|1[0-9][0-7])/

Avatar of ozo
You are not anchoring your regular expression

/^200\.100\.129.(\d|[123456789]\d|11[0123456789]|12[01234567])$/
or
/^200\.100\.129.(\d|[1-9]\d|11[0-9]|12[0-7])$/
Sorry, make that
/^200\.100\.129\.(\d|[1-9]\d|1[01]\d|12[0-7])$/
Actually, that also matches 200.100.129.0 whereas you said 200.100.129.1 to 200.100.129.127
do you want that fixed too?
The problem with /200.100.129.(\d|[123456789]\d|11[0123456789]|12[01234567])/
was that it matches e.g. 200.100.129.2, and 200.100.129.2 can be found in 200.100.129.255
Avatar of Electrotec

ASKER

ozo - thats a good point.

Revised request:

I require:
Group 1: 200.100.129.001 to 200.100.129.127
Group 2: 200.100.129.128 to 200.100.129.255

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial