5.4. Using Regular Expression Backreferences in Rules

Whenever a regular expression match is executed in a rule condition, the matched substrings can be later used in subsequent actions or conditions. The matched result is referred to by so called “backreferences”.

Backreferences are used by the replacement $B(c.r). The first index in the backreference, c, denotes the index of the condition, where the first condition has the index 1, the second condition the index 2, and so forth. The second index, r, denotes the index of the substring selection in the regular expression, where the first selection has the index 1, the second the index 2, an so forth.

In the following example, see Fig. Using backreferences, we use backreferences to separate protocol discriminator (“sip” or “tel”) from the rest of request URI. These two parts are matched in the regular expression in the 2nd condition and are therefore referred to as $B(2.1) and $B(2.2). Particularly, the example saves the protocol discriminator from the request URI in an INVITE request to a call variable called uri_scheme. Further it enforces the “sip” scheme for the R-URI of the outgoing INVITE request.

_images/10000000000003C5000003279AFABFB0.png

Figure 1: Using backreferences

Previous topic

5.3. Using Replacements in Rules

Next topic

5.5. Binding Rules together with Call Variables

This Page