• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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.
0
Electrotec
Asked:
Electrotec
1 Solution
 
manav_mathurCommented:
for group2

/200\.100\.129\.(1(?=(2(?=[8-9])|[3-9](?=\d)))|2(?=[0-5]))\d/
0
 
manav_mathurCommented:
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
0
 
geotigerCommented:

 for group1

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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ozoCommented:
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])$/
0
 
ozoCommented:
Sorry, make that
/^200\.100\.129\.(\d|[1-9]\d|1[01]\d|12[0-7])$/
0
 
ozoCommented:
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
0
 
ElectrotecAuthor Commented:
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
0
 
ozoCommented:
/^200\.100\.129\.(00[1-9]|0[1-9]\d|1[01]\d|12[0-7])$/
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now