Forum Discussion
Aurel
Cirrus
Jan 04, 2019iRule : matching 2 patterns in the query string but in order
Hello,
I would like to match 2 different patterns in the query string, but one before the other.
Example : http://www.example.com/test?pattern1=value1&pattern2=value2
The "pattern1" have to be ...
Stanislas_Piro2
Cumulonimbus
Jan 04, 2019of course it's possible. following lines are from tclsh for demo. you can use same if expression in irule.
% set uri_list {"/test?pattern1=value1&pattern2=value2" "/test?pattern2=value2" "/test?pattern1=value1" "/test?pattern2=value2&pattern1=value1"}
"/test?pattern1=value1&pattern2=value2" "/test?pattern2=value2" "/test?pattern1=value1" "/test?pattern2=value2&pattern1=value1"
% foreach uri $uri_list {
unset -nocomplain p1pos p2pos
For logging only because p2pos is not set if first condition fails in next line.
set p2pos [string first "pattern2=" $uri]
if {([set p1pos [string first "pattern1=" $uri]] != -1) && ([set p2pos [string first "pattern2=" $uri]] != -1) && ($p1pos < $p2pos)} {
puts "ok : $p1pos / $p2pos / [expr {$p1pos < $p2pos}]"
} else {
puts "Not ok : $p1pos / $p2pos / [expr {$p1pos < $p2pos}]"
}
}
%
ok : 6 / 22 / 1
Not ok : -1 / 6 / 1
Not ok : 6 / -1 / 0
Not ok : 22 / 6 / 0
%
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