- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
04-25-2018 07:12 AM
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
05-02-2018 10:25 AM - edited 05-02-2018 10:26 AM
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]"
05-02-2018 10:25 AM - edited 05-02-2018 10:26 AM
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]"
05-02-2018 11:41 AM
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]
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!