Regular Expressions and the SIP Protocol

Within the SIP Protocol, a SIP URI identifies a communications resource. All URIs, SIP URIs may be placed in web pages, email messages, or printed literature. They contain sufficient information to initiate and maintain a communication session with the    resource. SIP URI defined as sip:user@host.

 A. "user” - identifier of a particular client resource at the host being addressed.

 B. "host" - in this context frequently refers to a network domain. When using Regular Expressions to define a SIP URI, these expressions allow for the customization and flexibility to define SIP URIs as variables.

Let's take a look on an industry-standard regular expression notations:



Routing Calls using the Dial Plan 

The dial plan is used to instruct the B2BUA about the routing path of calls, who to accept calls from, match on, where calls are going to, and where to send the call. When we add regular expressions into the dial plan, it allows us to specify a range of numbers, domains, or other sets of specific digits.Regular expressions are a flexible way of delivering patterns that match a unique set of criteria. For example: [0-9]{7,} - this means any digits from 0 to 9, repeated a maximum of 7 times. This is a regular telephone number.


Regular Expressions in the Matching From Header


The purpose of the Matching From Header is to provide source SIP URI matching, as well as source Transport and Network Address. In the regular expression we create a criteria for the From Header SIP URI of the SIP message. This is used when matching requests in the Dial Plan. For a request to match all criteria must be met.     

Please see an example table:




Regular Expressions in the Matching Request URI

     The purpose of Matching Request URI is to match on the incoming Request URI Header of the SIP message that is being sent to SBC. Normally the "domain" portion of the URI is the SBC IP/fqdn.

      In regular expressions we create criteria for the Request URI of the SIP message. This is used when matching requests in the Dial Plan. For a request to match all criteria must be met.


      Port and Transport will match only if there are BOTH port and transport parameters contained in the SIP URI.





Regular Expressions in the Forward To

     The purpose of the Forward To attribute in the Dial Plan is to define where to send the SIP traffic. A specific destination SIP URI address is defined to forward the call to. The user and domain portions of the SIP URI are statically defined       to ensure that SIP traffic is relayed to the correct destination.

     We may enter here regular expressions to the dial plan, used to define where and how the firewall should forward the request using the dial plan.

     A regular expression refers to regular expression sub-expressions on the corresponding row in the MAtching Request-URI table.

      Sub-expressions are numbered in the order of their starting parenthesis and referred to as $number

      In the expression expression (sip:(.+)), which matches any Request URI like, there are 2 referablesub-expressions:

       1. sip:user - which is referred to as $1

       2. user - which is referred to as $2

      We can always refer to the entire Request URI with $0, as long as the match in the Matching Request URI table was made using a regular expression.


      We may define lines in the dial plan that lacks a Forward definition. This becomes useful in case when you forward by ENUM.