Forum Discussion

Idealf5's avatar
Idealf5
Icon for Nimbostratus rankNimbostratus
Jul 14, 2015

String after the last slash starts_with

Hi,

 

I need help with an IF-Statement that checks the first two characters after the last slash in the Uri. If it starts with a 'k' followed by a number (k[0-9]), then do something. If the second character after the 'k' is not a number then do nothing.

 

Examples: www.xyz.com/bla/blub/k20ab154 - Do something www.xyz.com/bla/blub/kab20154 - Do nothing

 

Thank you in advance

 

Sven

 

1 Reply

  • Here's one option that avoids regular expressions:

    when HTTP_REQUEST {
        if { [string index [HTTP::uri] [expr [string last "/" [HTTP::uri]] +1]] eq "k" } {
            if { [string is integer [string index [HTTP::uri] [expr [string last "/" [HTTP::uri]] +2]]] } {
                 second character after "k" is a number - do something
            }
        }
    }