match strings between delimiters

Hi

I do have an irule that contains:

if {$al_ctrl_parameter contains $switch_app_pool }
switch_aap_pool could contain myURI_A1 or myURI
al_ctrl_parameter could contain TEST=myURI_A1,myURI,myURI_A2,myURI_A3& (delimited with commas)

In that case if somebody would use the URI myURI it would match to all al_ctrl_parameter. How can I check with the if statement the strings between the delemiters (commas)?

thanx bb

Check out ‘split’ and ‘lsearch’ commands. DevCentral - An F5 Technical Community

if { [lsearch [split $al_ctrl_parameter ,] $switch_app_pool] } then {
   do something
}

If you want to exact string matches add the -exact parameter to lsearch otherwise it’ll match partial strings

My bad, it should be: ~~~ if { [lsearch -exact [split $al_ctrl_parameter ,] $switch_app_pool] >= 0 } then { do something } ~~~

Hi Dan

Thank you first for answering but there is one more challange. As you can see:

al_ctrl_parameter looks like  TEST=myURI_A1,myURI,myURI_A2,myURI_A3&

So, with split

set testSPLIT [split $al_ctrl_parameter ,]

log local0. "testSPLIT: $testSPLIT"

araSPLIT: TEST=myURI_A1 myURI myURI_A2 myURI_A3&

I should only build a list between the = and & without them like:

myURI_A1 myURI myURI_A2 myURI_A3

and the $switch_app_pool variable could contain one of these but should exact match against just one.

I don’t know how to achieve this… Would be great if you could help!

Thank you bb

@bigbrother - if your $al_ctrl_parameter is the query string from a URL request (ie, it begins with a “?” and is in the format of “?param1=value1&param2=value2&…” then you can use the URI::query command to pull the value for “param1”, “param2”, etc. You can then split the string into tokens with your delimiter (in your case it looks like commas). So, something like this should help

set query "?P1=V1&TEST=myURI_A1,myURI,myURI_A2,myURI_A3&P2=V2";
set test_value [URI::query $query "TEST"]
set value_list [split $test_value ","]

The contents of “value_list” should be {myURI_A1 myURI myURI_A2 myURI_A3}.

Keep in mind that if the value of $query doesn’t start with a “?” then the URI::query command won’t return anything.

Hope this helps…

-Joe

Hi Joe

Thank you for your response. No $al_ctrl_parameter is not form a URI query. It is just a variable I fill up from a cookie and it contains exactly “TEST=myURI_A1,myURI,myURI_A2,myURI_A3&”.

So, I think URI::query is not the thing I need. Should be something that I can grab the string between = and & and then using split command.

You could always prepend the string with a “?” and then use the URI::query command and make it look like a query string.