Forum Discussion
jay_41157
Nimbostratus
Dec 17, 2008double wildcard match for uri patterns
Hi,
Is it possible to use 2 wildcards when checking for a uri ?
For ex,
I want to look for
uri1abcURI2zzz
uri1xxxURI2wqq
so for the above can I do....
uri1*xxxURI2*
maybe with reg expressions ?
Thanks,
Jay
10 Replies
- hoolio
Cirrostratus
Hi Jay,
You can use string match with multiple wildcards:string match -nocase "*pattern*" "some string"
Or you could use the -glob flag for switch:switch -glob [string tolower [HTTP::uri]] { "uri1*xxxURI2*" { ...
Either string-based option would be more efficient than a regex.
Aaron - jay_41157
Nimbostratus
Aaron,
Thanks for the response. However I am unclear on the syntax...
how does the below look?
if { [HTTP::uri] equals string match -nocase "portal/aaa/org/memberapp?*pageLabel=application*" } {
HTTP::redirect http://redirecttotaget
}
All I have a total of 3 patterns that i will need to check for... so should I just use or statements ? or try and integrate this with a matchclass I had run into problems using a wildcard with a match class in the past.
Thanks - hoolio
Cirrostratus
If you have multiple patterns you want to check, a switch statement would help keep them organized:when HTTP_REQUEST { Check requested URI switch -glob [HTTP::uri] { "*pattern1* - "*pattern2* - "*pattern3* { Execute this code for the first three patterns HTTP::redirect "http://first_redirect.example.com" } "*pattern4* - "*pattern5* { Execute this code for the next two patterns HTTP::redirect "http://second_redirect.example.com" } default { Execute this code for the any cases that haven't been matched HTTP::redirect "http://default_redirect.example.com" } } }
Else, if you wanted to use a single if statement you could do something like this:when HTTP_REQUEST { Check requested URI if { ([string match -nocase "portal/aaa/org/memberapp?*pageLabel=application*" [HTTP::uri] ]) \ or ([string match -nocase "*pattern2*" [HTTP::uri]]) \ or ([string match -nocase "*pattern3*" [HTTP::uri]])}{ log local0. "[IP::client_addr]:[TCP::client_port]: Matched check for [HTTP::uri]" HTTP::redirect http://redirecttotaget } }
Aaron - jay_41157
Nimbostratus
great, thanks. which option is more efficient in the irule ?
Thanks - hoolio
Cirrostratus
I've read in the forums and an old article (Click here) that an if statement is more efficient than a switch for a handful of comparisons. After that a switch is more efficient. At some point (around 100 elements) a datagroup would be more efficient than a switch. I haven't actually tested this before though.
I'd guess the difference isn't huge for a handful of comparisons. I think it's more important that you use a form that's easy for you to read.
If speed/resource usage is critical for you, you can test the versions using the timing command (Click here).
Aaron - jay_41157
Nimbostratus
I dont think for this specific change we are at the point where speed / resource usage is an issues since this will be in place only for a couple of hours.
I was curious if one was better over the other.
Thanks for your help. - jay_41157
Nimbostratus
if i use:
or ([string match -nocase [HTTP::uri] "/portal/acs/corg/memberapp?jay"]) that works, however if I use:
or ([string match -nocase [HTTP::uri] "/portal/acs/corg/memberapp?*jay=*"])}{ -- seems like the * does not work as a wildcard...
any thoughts ?
thanks - jay_41157
Nimbostratus
the 1st or the second wild card neither of them are matched.
/portal/acs/corg/memberapp?*jay=*
I tried to use the below uri to test:
/portal/acs/corg/memberapp?111jay=222; this does not match, I try to swap the *'s individually and same results. I will try to use \ for escaping ?
Thanks - jay_41157
Nimbostratus
using:
or ([string match -nocase [HTTP::uri] "/portal/acs/corg/memberapp/jay?*"])}{
I get the * to work as a wild card.. what I need is to have a string append at the end of the wild card . - hoolio
Cirrostratus
Sorry... I had the pattern and string reversed in my last post. It should be:
string match -nocase $pattern $string_to_compare
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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