Forum Discussion
DM_5174
Nimbostratus
Jul 09, 2007<b>Better way to code iRule in 4.5.x code ???</b>
Hi all,
I have version 4.5x code and would like to know if there is any efficient way to
consolidate the code below. I tired to use tolower or class but got an error message. I believe ...
Martin_Machacek
Jul 09, 2007Historic F5 Account
Regular expressions are the least efficient way of matching in
iRules (especially in v4.x). The regex version of the rule is very likely going to be measurably slower than the if-then chain. The most efficient way to match an item of a set in an iRules is to use classes. Like this:
class apache_sites {
"site1"
"site2"
"site3"
"site4"
"site5"
"site6"
"site7"
}
rule match_apache_sites {
if( http_uri contains one of apache_sites) {
use pool APACHE_POOL
} else {
use pool IISWEB-POOL
}
}NOTE: the above rule matches also URIs containing the items of the class as substring (e.g. "site666" or "parasite1"). If those matches are not desired, you need to either add delimiting characters to the items in the set (e.g. "/site1/"), use other match operator (e.g. "starts_with", "equals" or "ends_with) or use the substr function to extract the portion of the URI to be matched.FYI, the tolower function is available only in 4.6.x.
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