Regular Expressions Tip for Interaction Gateway or SIP Proxy

When setting up a route for Interaction Gateway or Interaction SIP Proxy you use Perl regular expressions to define the route patterns.

My classroom environment in Indianapolis has over 100 IC servers, each with its own range of phone numbers.  My 4.0 servers, for example, each have 20,000 different phone numbers assigned.  I really don’t want to have to create one route for each phone number on each server!

Let’s take a single server as an example.  ICServer01a needs to receive calls to 1317201xxxx, 317201xxxx, 201xxxx, 1702201xxxx, and 702201xxxx where xxxx is the range 0000-9999.  If I were to set up a route for the 1317201xxxx form of the number, it might look like:

1317(201[0-9][0-9][0-9][0-9]) on the IGateway inbound route or sip:1317(201[0-9][0-9][0-9][0-9])@.* on the SIP Proxy route (technically the SIP Proxy does not need the “sip:” because it automatically tries both with and without that formatting, but I like to stay clean).

Now, the formatting used above is purposely exaggerated to prove a point – too many characters.  Perl regular expressions are designed to be more compact.

For example, instead of the four sets of [0-9] I could use [0-9]{4} to give the range and signify that it is repeated four times.  With that formatting I could create my routes thus:






All of those would route to “sip:$” with the 1$ representing the first set of parentheses in the regular expression (BTW, $0 represents the whole expression).  We use a 7-digit DNIS in this scenario.

Now, I have a little bit of efficiency by the {4} formatting, but I’m still not happy with five routes.  I want one.  That’s where designating portions of the expression as optional comes in.

To cut to the chase, I can use a “?” to designate a character of range of characters as optional:

1?(317)?(201[0-9]{4}) can replace the first three routes above with a single route pattern.  I have added a pair of parentheses, so now my destination will be “sip:$”

Being the person I am, however, that’s not good enough.  I want a single route, for which I am willing to take a little bit of risk.  In my environment there is no published phone number which starts with “317702”, so I am going to combine my routes using one more optional parameter:

1?(317)?(702)?(201[0-9]{4}) and route to “sip:$” (again, using a 7-digit DNIS).

I’m still not satisfied, because I read the Perl tutorial, and found that I can get rid of three more characters from my pattern. “d” is used to represent any number 0-9:


Isn’t that pretty? (Or just pretty confusing…?)

I’m sure folks out there could refine it even more, but that’s as far as I have gone.

Hopefully that helps someone out there.  Now I’m off to finish preparing the lab environment for Interactions 2012!


George Ganahl, aged InIn employee #162 (boy, do I feel old with all the kids I see around here)

George Ganahl

George Ganahl

I joined Interactive Intelligence in March 1999 with a background in technology and data networking. My first stop was in education, where I taught our partners and customers how to install, configure and administer our IP business communications software system. Several years on the development side of the house followed, where I managed the install, build and documentation teams; built hotfixes; managed our software platform; and maintained the big picture for development. After a return to education, I managed and maintained the worldwide set of classroom equipment and continued to train partners and customers. These days I’m concentrating on internal training for the services teams, including training for our new multitenant cloud platform, PureCloud℠, which delivers customer engagement, and unified communications and collaboration services.