• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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