Regular Expressions as Boolean Expressions

Regular expressions can be used as boolean expressions today if they are the only value being compared against a string, as is shown in the case below.

mime-rule
        name                           someMimeRule
        content-type                   application/text
        action                         replace
        comparison-type                pattern-rule
        match-value                    ^every good boy .*
        new-value                      every good girl does fine
However, regular expressions can not be used in conjunction with other boolean expressions to form more complex boolean expressions, as is shown below.

mime-rule
     name                      someMimeRule
     content-type              application/text
     action                    replace
     comparison-type           boolean
     match-value               $someRule & ^every good boy .*
     new-value                 every good girl does fine

There are many cases where the user has the need to compare some value as a regular expression in conjunction with another stored value. It is possible to perform this behavior today, however it requires an extra step in first storing the value with the regular expression, followed by another Manipulation Rule which compares the two boolean expressions together (e.g. $someRule & $someMimeRule).

In order to simplify the configuration of some sip-manipulations and to make them more efficient this functionality is being added.

Unfortunately, it is not possible to just use the example as is shown above. The problem is there are many characters that are commonly used in regular expressions that would confuse the HMR expression parser (such as $, and +). Therefore delimiting characters need to be used to separate the regular expression from the other parts of the expression.

To treat a regular expression as a boolean expression, it needs to be enclosed within the value $REGEX(<expression>,<compare_string>=$ORIGINAL); where <expression> is the regular expression to be evaluated. <compare_string> is the string to compare against the regular expression. This second argument to the function is defaulted to $ORIGINAL which is the value of the of the specific Manipulation Rule object. It can be overridden to be any other value the user desires.

The proper configuration for the example above to use regular expressions as boolean expressions is

mime-rule
        name             someMimeRule
        content-type     application/text
        action           replace
        comparison-type  boolean
        match-value      $someRule & $REGEX(“^every good boy .*”)
        new-value        every good girl does fine

It is also possible to use expressions as arguments to the $REGEX function. These expressions will in turn be evaluated prior to executing the $REGEX function. A more complex example is illustrated below.

header-rule
        name              checkPAU
        header-name       request-uri
        action            reject
        comparison-type   boolean
        match-value       (!$REGEX($rule1[0],$FROM_USER))&
                          (!$REGEX($rule2[0],$PAI_USER))
        msg-type          request
        new-value         403:Forbidden
        methods           INVITE,SUBSCRIBE,MESSAGE,PUBLISH,
                          OPTIONS, REFER

It should be noted that when using $REGEX() in a boolean expression, the result of that expression is not stored in the user variable. The comparison-type must be set to pattern-rule in order to store the result of a regular expression.

The arguments to the $REGEX() function are interpolated by default. This is the case since the arguments themselves must be evaluated at runtime. The following example is also valid.

mime-rule
        name                someMimeRule
        content-type        application/text
        action              replace
        comparison-type     boolean
        match-value         $someRule & $REGEX(“^every good
                            {$rule1[0].$0} .*”)