Forum Discussion
Matt_Breedlove_
Jul 17, 2012Nimbostratus
switch glob tcl string match support
Hi All
When using switch -glob, I know it supports square bracket char ranges such as [a-f], but does it support either of these?
Either "a" or "d" or "f"
[a,d,f]
or
Either "a" or "d" or "f"
{a,d,f}
or am I stuck with a more broad? [a-f]
This tcl man page below references the curly brace way, but its not mentioned in the usually quoted tcl man page on these forums
http://www2.tcl.tk/3264
Thanks
- Michael_YatesNimbostratusHi Matt,
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/test[a,c,e]" { HTTP::redirect "http://www.google.com" } "/test[b,d,f]" { HTTP::redirect "http://www.yahoo.com" } } }
- hooleylistCirrostratusI thought I replied to this yesterday. Somehow it got lost in the ether.
switch -glob $letter { a - d - f { Matched a d or f } } Or: switch -glob $letter { [adf] { Matched a d or f } }
- Matt_Breedlove_NimbostratusHi Aaron,
when HTTP_REQUEST { set pool8777 "suia-p.testms1_8777" switch -glob [URI::decode [string tolower [HTTP::uri]]] { "*/vz*" { return } "/csp*xpf=7*" { if { [class match [string tolower [HTTP::header "User-Agent"]] contains sms1p_ua_blacklist] } { drop } else { return } } "/spf/*" { pool $pool8777 } "/csp*f[a-c][a-e]*[b-c]*o*k" - "/csp*kw=??aceb*k" - "/csp*kw=?aceb*k" - "/csp*f[a-b][c-j][b-e]*oo" - "/csp*f[a-b][l-n][b-e]*oo" - "/csp*kw=fb[&, ,.]" - "/csp*f?a?c?e" { HTTP::redirect "http://cs.testams1.com/spf/cs_sms1_facebook.asp?[HTTP::uri]" } "/csp*kw=goo[&, ,.]" - "/csp*[g,6][e,o,0][g,o,0,r][g,l,o]ul" - "/csp*[g,6][e.o.0][g,o,0,r]gl" - "/csp*[g,6][e,o,0][g,o,0][g,l,o][e,g,l,o]" { HTTP::redirect "http://cs.testams1.com/spf/cs_sms1_google.asp?[HTTP::uri]" } default { if { [class match [string tolower [HTTP::header "User-Agent"]] contains sms1p_ua_blacklist] } { drop } else { return } } } }
- Matt_Breedlove_NimbostratusThe "&" in the above code box was a literal ampersand on post, but the forum swapped them out.
- Matt_Breedlove_NimbostratusAh, think I figured out the issue. I've used switch's on URI's for a long time, but usually I don't double quote the URI in the match, but figured it was better to do that
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects