Forum Discussion

Nick_T1's avatar
Nick_T1
Icon for Nimbostratus rankNimbostratus
Feb 18, 2016

String match unexpected behavior

Hello all! I'm trying to implement string match for the following condition and am not coming up with the right combination of options and looking at tcl wiki didn't yield anything yet. In one irule (traffic_split), I setup a pattern and in my final irule (pool_mapping) I check for this test condition and override if it is met. The following works (I know its not exactly regex)

excerpt from traffic_split:

set test_host "www.fool.com"
set test_path_regex "\/investing\/general\/2016\/*"
set test_percentage 10

excerpt from pool_mapping:

  if {[info exists test_cookie_name]}{
    if {[HTTP::cookie exists $test_cookie_name] && $host equals $test_host && [string match -nocase $test_path_regex $path] }{
      if { [HTTP::cookie value $test_cookie_name] <= $test_percentage }{
        set tmfpool $test_pool
      }
    }
  }

So, when requesting this URL, it works: http://www.fool.com/investing/general/2016/02/09/the-agony-of-high-returns.aspx

However, the developers of the application noted that there was some errant traffic being sent to them, example: http://www.fool.com/investing/general/2016/02/09/atom.xml

So, I thought just using something like one of the following, none of which worked:

set test_path_regex "\/investing\/general\/2016\/*\.aspx"
set test_path_regex "\/investing\/general\/2016\/.*\.aspx"
set test_path_regex "\/investing\/general\/2016\/*\.aspx$"
set test_path_regex "\/investing\/general\/2016\/.*\.aspx$"

Am I missing something, unimplemented by design, or something else entirely?

  • Hi Nick,

    the command

    [string match -nocase $test_path_regex $path]
    isn't using RegEx. Its rather using a
    -glob
    matching syntax (
    *
    ,
    ?
    or
    [A-Za-z0-9]
    wildcards). So just use...

    set test_path_regex "/investing/general/2016/*.aspx"
    set test_path_regex "/investing/general/2016/*.aspx*"
    

    For more information: http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM34

    General Note: You should avoid using RegEx in iRules as much as possible. Its terible slow and most of the stuff can be already done using -glob matchings.

    Cheers, Kai