Forum Discussion
Wil_Schultz_101
Nimbostratus
Dec 13, 2007Fun with regexp...
Just ran into a fun little problem, thought I would share and maybe ask if there is a better/more efficient way to do this.
Problem:
URI that are either 4 or 5 digits in length, and may or may not end with a trailing slash, go to a certain place under a hidden URI
Exception:
URI that the first 4 digits are 1900-2099 and may (or may not) have another number afterwards, and URI that are more then 5 numerals in length are also exceptions and go to another pool.
Solution:
when HTTP_REQUEST {
set uri1 null
set uri2 null
regexp {^/(19[0-9][0-9]|20[0-9][0-9])[0-9]?} [HTTP::uri] uri1
regexp {^/[0-9]{4}[0-9]?/?$} [HTTP::uri] uri2
if {!($uri1 == "null") } {
log "... 1 $uri1"
pool pool1
return 0
}
if {!($uri2 == "null") } {
regexp {[0-9]*/?$} [HTTP::uri] uri3
log "... 2 $uri2 $uri3"
HTTP::uri "http://www.domain.com/cgi-bin/dosomething.cgi?url=$uri3"
pool pool2
return 0
}
}4 Replies
- JRahm
Admin
...or more fun WITHOUT regex!
Nice post for the toolbox, Joe. string is integer is a new one for me. - Wil_Schultz_101
Nimbostratus
Interesting, I'll find some time and give it a spin to see if it works the same.
Any idea if this is more efficient then the regexp? - An infinite loop is more efficient than a regexp. We'll not quite, but close B-).
-Joe Posted By citizen_elah on 12/14/2007 9:26 AM
...or more fun WITHOUT regex!
Nice post for the toolbox, Joe. string is integer is a new one for me.
Learn something new every day!
Just make sure you use the -strict option or else empty strings will always return true.
-Joe
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
