Translation rule

CLD (dnis) Translation Rule is Perl matching operator s///; Used for adjusting dialed number to match VoIP standards.

For example: remove 011 international dialing prefix, etc.

Translation rule syntaxis

s/<match string>/<replace string>/;

 

 

You can apply several translation rules sequentially:

 

s/<match string 1>/<replace string 1>/; s/<match string 2>/<replace string 2>/; ....

 

 

metacharacters:

/

Quote the next metacharacter

^

Match the beginning of the line

.

Match any character (except newline)

$

Match the end of the line (or before newline at the end).

|

Alternation

()

Grouping

[]

Character class

 

 

quantifiers:

*

Match 0 or more times.

+

Match 1 or more times.
?

Match 1 or 0 times.

{n}

Match exactly n times.

{n,} Match at least n times.
{n,m} Match at least n but not more than m times.

[]

Character class.

 

 

By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a "?". Note that the meanings don't change, just the "greediness":

 

*?

Match 0 or more times.

+?

Match 1 or more times.
??

 Match 0 or 1 time.

{n}?

Match exactly n times.

{n,}? Match at least n times.
{n,m}?

Match at least n but not more than m times.

 

The bracketing construct ( ... ) creates capture buffers. To refer to the digit'th buffer use \ within the match. Outside the match use "$" instead of "\".

Examples:

Replaces 0 in the beginning of number with 86:

 

  s/^0/86/;  

 

 

Removes international dialing prefix:

 

s/^011//;  

 

 

Previous two actions in one go:

 

s/^011//; s/^0/86/;

 

 

Swaps first two words:

 

s/^([^ ]*) *([^ ]*)/$2 $1/;

 

NOTE: particularly complicated regular expressions can take exponential time to solve because of the immense number of possible ways they can use backtracking to try match. For more information on regular expressions see: http://perldoc.perl.org/perlre.html

 

 

Translation Rules for IVR Applications

 

When defining translation rules for IVR applications, use Python regular expressions. Their syntax is similar to that of Perl, however, use \\n within the match to express backreferences: \\1 \\2 etc.

 

Note that Python regular expressions are used only to translate numbers in calls to IVR applications (e.g. prepaid card calling, callback calling, etc.) Web, SMS and Email callback triggers utilize Perl regular expressions.

Thus, the Perl regular expression to swap the first two words looks like this in Python:

 

 s/^([^ ]*) *([^ ]*)/\\2 \\1/;

 

For more information on Python regular expressions see: https://docs.python.org/2/howto/regex.html