Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reg expression help 1

Status
Not open for further replies.

GUJUm0deL

Programmer
Joined
Jan 16, 2001
Messages
3,676
Location
US
I am using Google analytical system on my site, and I have an IP range which i'd like to forego in the reports. According to google ( I can define the IP range via reg expression. I haven't used reg expression in a long time, so I need some help.

If my IP range is: 127.11.123.1-254 and 127.22.456.1–254 then how should my reg expression look?

Thanks!


____________________________________
Just Imagine.
 
I figured I'd start this off. Not much testing, but the ones I tested passed the test. Add more to the array to continue...

Code:
<script type="text/javascript"><!--

var re = /^127\.(11\.123|22\.456).([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])$/;

var ip = new Array('126.0.0.1', '127.0.0.1', '127.11.123.1', '127.22.123.1','127.11.123.456','127.22.456.23');

for ( var i = 0; i < ip.length; i++ ) {
    document.writeln(ip[i] + " test: " + re.test(ip[i]) + "<br />");
}

//--></script>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for the help!

Your're example is very different then the one Google provoides. Google says to do it as:
Code:
192.168.1.1-25 and 10.0.0.1-14 

then the IP address value will be: 

^192\.168\.1\.([1-9]|1[0-9]|2[0-5])$|^10\.0\.0\.([1-9]|1[0-4])$

The difference is my scenario has 3 digits in the range and google's example has 2. (mine is 1-254 and Google is 1-25)

____________________________________
Just Imagine.
 
Would this be correct also:
Code:
^127\.11\.123\.([1-9]|1[0-9]|2[0-5]|25(0-4))$|^127\.22\.456\.([1-9]|1[0-9]|2[0-5]|25(0-4))$

____________________________________
Just Imagine.
 
My boss wants the IP range to be in the same manner as Google cites in their example.

____________________________________
Just Imagine.
 
no.

1[0-9] means 10 - 19. what about 22, 23, 35, 46...

25(0-4) will match "250-4".

was there something wrong with the RE i provided?



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
There was nothing wrong with the code you provided. If it was up to me i'd use it. But my boss is iffy about it, keeps saying 'why does Google show it differently?' My fear is that if the Google Analytical doesn't work right, my boss is going to be like 'its the ip range that caused it to not work right' (I know, I know but HE is the boss)

How can I re-write it so that it mocks what Google cites (this is to shut him up so I can do go back to developing)


____________________________________
Just Imagine.
 
If your boss doesn't like the working solution that Cory provided, then tell him to do it himself. [lol]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Hi, could you explain what this part means:

([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])

____________________________________
Just Imagine.
 
If your boss doesn't like the working solution that Cory provided, then tell him to do it himself.

LOL, I wish I could. If I did that, i'd be waiting online at the unemployment office, lol

____________________________________
Just Imagine.
 
[red]single digit between 1 and 9 (matches 1-9)[/red]
[blue]one digit between 1 and 9, followed by one digit between 0 and 9 (matches 10-99)[/blue]
[green]1 followed by one digit between 0 and 9, followed by one digit between 0 and 9 (matches 100-199)[/green]
[teal]2 followed by one digit between 0 and 4, followed by one digit between 0 and 9 (matches 200 - 249)[/teal]
2 followed by 5 followed by one digit between 0 and 4 (matches 250-254)

have i passed initiation yet?



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])

1 thru 9
OR
1 thru 9 followed by 0 thru 9
OR
1 followed by 0 thru 9 followed by 0 thru 9
OR
2 followed by 0 thru 4 followed by 0 thru 9
OR
25 followed by 0 thru 4

consequently, all [!][0-9][/!] can be replaced by [!]\d[/!] - it means the same thing.

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
[lol] Then I guess this won't work:
Code:
var re = /^127\.(11\.123|22\.456).([1-9]|[1-9][!]\d[/!]|1[!]\d{2}[/!]|2[0-4][!]\d[/!]|25[0-4])$/;
[smile]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
What is it an ip address with .456?
 
Thanks for the quick lesson in RE! :-)

I am still using the example cLFlaVA provided. If my boss an an issue, i'll deal with it when the time comes.

tsuji, the IP range I used in this thread was a dummy one. Obviously, since .456 isn't a valid range, :-)

____________________________________
Just Imagine.
 
I see... then it's fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top