Regex Issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Regex Issue

L0 Member

 

Hey Everyone,

 

I am having an issue that I can't explain.  I am building a signature to match on IP addresses in the X-Forwarded-For Http header.  what I have come up with is this: "For: 1\.2\.[3-4]\..*"  This is working well, but I am having an issue with certain ranges I have one that is "For: x\.x\.[176-179]\..*"  this throws an invalid pattern error and I have it narrowed down to the actual range of 176-179.  If I switch that to be [170-179] it accepts the pattern fine.  Has anyone seen this issue before?  If so how did you fix it?

 

Thanks,

Dave

1 accepted solution

Accepted Solutions

L4 Transporter

the [] operators do not work the way you think in regex.

 

[170-179] means "1, or 7, or a number between 0 and 1 inclusive, or 7 or 9"

therefore, [176-179] means "1, or 7, or a number between 6 and 1 inclusive (this is invalid), or 7, or 9

 

put another way, the [] operators mean "one of these characters"

 

to match numbers between 176 and 179, inclusive you should have "17[6-9]"

View solution in original post

2 REPLIES 2

L4 Transporter

the [] operators do not work the way you think in regex.

 

[170-179] means "1, or 7, or a number between 0 and 1 inclusive, or 7 or 9"

therefore, [176-179] means "1, or 7, or a number between 6 and 1 inclusive (this is invalid), or 7, or 9

 

put another way, the [] operators mean "one of these characters"

 

to match numbers between 176 and 179, inclusive you should have "17[6-9]"

Thank you for the answer.  I figured it out just this morning as well.  There is another option which is to use hex in place of the integers so that 176-179 becomes [\xB0-B3\x]

  • 1 accepted solution
  • 3396 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!