Forum Discussion
David_Noonan_67
Nimbostratus
Oct 08, 2007Syntax for "matches" and "matches_regex"
We've got an iRule that contains the following code. It works fine but I find the repetition offensive.
elseif {[HTTP::uri] contains "fx1"} {
use pool Xyzzy
}
elseif {[HTTP::uri] contains "fx2"} {
use pool Xyzzy
}
elseif {[HTTP::uri] contains "fx3"} {
use pool Xyzzy
}
elseif {[HTTP::uri] contains "fx4"} {
use pool Xyzzy
}
I thought this could be replaced with something like this
elseif {[HTTP::uri] matches "fx[1234]"} {
use pool Xyzzy
}
but it complains about"extra tokens at end of expression". So I tried this
elseif {[HTTP::uri] matches_regex "fx[1234]"} {
use pool Xyzzy
}
But that complains about an undefined procedure.
Can someone point me at a working example of the matches and/or matches_regex using a character range? The examples shown on the wiki are overly simple and therefore not very useful.
Thanks
6 Replies
- Deb_Allen_18Historic F5 AccountUse {} to delimit the match expression instead of "" and you should be good to go:
(wiki example updated)elseif {[HTTP::uri] matches_regex {fx[1234]}} { use pool Xyzzy }
- Deb_Allen_18Historic F5 Accountboy, some funky substitution is taking place there....
- Deb_Allen_18Historic F5 AccountJust realized you'd have to also include some wildcards if you want to simulate the "contains" command:
elseif {[HTTP::uri] matches_regex {.*fx[1234].*}} { use pool Xyzzy }
- Deb_Allen_18Historic F5 AccountBraces may be used to prevent interpretation of strings surrounded by [] as commands, as you experienced ("undefined procedure").
- hoolio
Cirrostratus
Deb, thanks for the link to Colin's tips on avoiding conversions...elseif {[string match {*fx[1-4]*} [HTTP::uri]]} { pool Xyzzy }
when HTTP_REQUEST { switch -glob [HTTP::uri] { {*fx[1-4]*} { pool test_http_200_pool} } }
- Deb_Allen_18Historic F5 AccountLooks like Joe fixed the character display substitution issue - thanks Joe!
if {"testfx4xxx" matches_regex ".*\[1234\].*"} {
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