Forum Discussion

Greg_Nance_3318's avatar
Greg_Nance_3318
Historic F5 Account
Dec 17, 2004

Using Regular Expressions in v9.x iRules

Versions of BIG-IP prior to version 9.x used a proprietary (fancy speak for "made up") syntax for creating iRules. One of the functions that was provided was the "matches_regex" function. While this function has been moved into version 9.x there is a much easier way to do this which leverages the TCL language.

Here is an example which I cooked up for a customer that makes use of the built-in regexp function in the TCL language to check a URL for a regular expression and make a decision based on the result.

 
 rule c180314 { 
    when HTTP_REQUEST { 
       if { [regexp -nocase {^/nl/app_1} [HTTP::uri]] } { 
          log local0. "[HTTP::uri] - Matches '/nl/app_1'." 
       }  
       elseif { [regexp -nocase {^/uk/app_2} [HTTP::uri]] } { 
          log local0. "[HTTP::uri] - Matches '/uk/app_2'." 
       } 
       elseif { [regexp -nocase {^/.*/app_unknown} [HTTP::uri]] } { 
          log local0. "[HTTP::uri] - Matches '/.*/app_unknown'." 
       } 
    } 
 } 
 

Greg
No RepliesBe the first to reply