regex issues

I have the following iRule switch statement:

[CODE]

switch -regexp [string tolower [HTTP::uri]] {

“/first/url/files/[1-9][\d]{0,6}” {

log local0. “You passed URL inspection!”

}

default {

reject

}

}

[/CODE]

I believe this should match the following URI: “/first/url/files/1000000”

However, it is also matching a URI like this: “/first/url/files/1000000000000000000000000000000000000”

Any ideas on this one?

I believe the problem is that you’re not specifically evaluating to the end of the string. You need to use the “$” character at the end to indicate “to end of string”.

when HTTP_REQUEST {
     switch -regexp [string tolower [HTTP::uri]] {
        "/first/url/files/[0-9]{0,7}$" {
        log local0. "You passed URL inspection!"
    }
    default {
        reject
        log local0. "rejected"
    }
}

This will catch any numeric value from nothing to 1000000. Change the evaluation to {1,7} if you want to make sure there’s at least one digit in the string.

Thanks!

That was it. Still surprised that it would continue matching indefinitely, but there you have it.

Not sure why my code blocks look all a mess with HTML…