Forum Discussion
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
isn't using RegEx. Its rather using a[string match -nocase $test_path_regex $path]
matching syntax (-glob
,*
or?
wildcards). So just use...[A-Za-z0-9]
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
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com