Advanced trigger conditions using regular expressions

This article will cover more complex trigger conditions. We'll take you through an example scenario to demonstrate how trickier use cases can be solved by using regular expressions.

The Scenario

A business wishes to test the numbers their callers dial. They have various lines to serve a number of European territories. Their numbers for Germany and Austria begin with their respective country calling codes: 49 and 41.

Somewhere in their call flow an IVR menu has been configured to allow callers to choose between two lines: "Press 1 for sales, or press 2 for support". The business has German-speaking teams for sales and support, and English-speaking teams to handle all other calls.    

The business therefore needs to make separate agent selections for the DE sales team, the DE support team, the EN sales team and the EN support team.

The agent selections can logically only be made with one trigger, however, so we must build both 'ANY' and 'AND' conditions into it, something which is not normally possible. Take for instance the trigger for the DE support team. In everyday speech, we want the trigger to say: "If the caller dialed a phone number beginning with EITHER 49 and 41, AND pressed 2 in the menu, pull this trigger."

Regular expressions are rules which evaluate whether a string of numbers match the rule's conditions. They offer the possibility of testing multiple conditions at once. Let's take a look at what the trigger just mentioned would look like on babelforce:

The bottom condition is simply testing the caller's dial pad input choice at the IVR menu. But what is that above it?!


If we break the expression down, it begins to look less intimidating:

  • ^_______$ ...... These characters are merely formal. They mark the start and end of the string.
  • (49|41) ...... Since this bit comes first, this tests whether the string begins with 49 or 43. The "|" is a pipe function, which here essentially means "or".
  • [0-9]* ...... This part just checks that the string is made of the numerical characters 0 to 9, the asterisk allowing the string to be of any length.

According to the trigger above, a customer in Austria dialing 41123456789 and a customer dialing 49123456789 (provided they both press 2) will both pull the trigger for the DE support team.

The business will need the corresponding inverse triggers as well, in order to achieve the same thing with the EN team selections. For the EN sales team, for example, they will require a trigger which says "If the caller dialed a phone number NOT beginning with EITHER 49 and 41, AND pressed 1 in the menu, pull this trigger."

In this case the regular expression uses a special operator at the beginning to test the prefix:


If the 'To number' (i.e. number dialed) is a string of any length which DOES NOT begin with 49 or 41, then it will match this regular expression. The trigger for EN sales would therefore look like this:


Note that regular expressions like those above are very useful for other tests too. You can imagine a scenario where you would like the trigger to see whether the number dialed was one of multiple inbound numbers you operate:


Or to test whether an IVR input - for example a customer reference number - is valid, by testing the first few characters and its length:


where "\d{x,y}" will make the string match only if it is between x and y characters long.

Test out your own regular expressions at  

Have more questions? Submit a request