Feedback

  • Contents
 

Using Regular Expressions

Regular expressions can be used to find patterns within text. In Interaction Dialer Manager, regular expressions can be used in Policy Conditions, Policy Behaviors, and to examine string attributes. For example, to create a condition that searches for a phone number, you might use this expression:

(((\([\d]{3}\))|([\d]{3}))-?)?\d{3}-?\d{4}

This expression searches for a pattern that has at least seven digits, optionally including dashes and an area code, with parentheses around the area code optional as well. In a pre-call Policy Condition for example (see figure below), the phone number (123)-555-5555 is a match for this expression, so the condition is satisfied.

Fine Tuning Regex matches

Note that something like "aaaabbc(123)-555-5555absde" is a match as well, since the pattern appears within the text. That can be fixed by adding ^ to the beginning of the expression, and $ to the end. This ensures that the expression will match a phone number only when it is itself the entire text.

These rules are specific to the style of regular expression, of which there are several. Regular expressions in Dialer use Perl syntax. There are many tutorials online if you wish to learn more.

For more information on creating regular expressions, see the Regular-Expressions.info Web site at: http://www.regular-expressions.info/

Using Regex in Policy Behaviors

For Policy Behaviors, three macros correspond to the regular expression condition. To select these macros, create a Policy Set Item Behavior, and then click the Macros button to open the Macro dialog. (For more information, see the Macros topic.)

The Regex macros are:

Macro Name

Purpose

RegexPrefix

Returns all the text that comes before a match

RegexSuffix

Returns all the text that comes after a match

RegexSubexpressionMatch

Returns the text that matches a particular sub-expression

Each macro requires a regular expression condition. In the case of RegexSubexpressionMatch, the dialog prompts for the specific sub-expression you wish to return results for. A sub-expression is a part of a regular expression that is enclosed in parentheses.

Using our previous example, the sub-expressions (numbered depth first, or in other words, more nested to less nested, left to right) are:

Expression

Result

(\([\d]{3}\))

Matches area codes with parentheses

([\d]{3})

Matches area codes without parentheses

((\([\d]{3}\))|([\d]{3}))

Matches either of the above

(((\([\d]{3}\))|([\d]{3}))-?)

Matches either of the above with optional dash suffix

Text Substitution Example

A good use of these macros is text substitution. For example, say we have a call attribute with a value as follows: "Regular expressions are great and you know it." Great doesn't describe it well enough, let's use awesome instead. Simply create a behavior with the attribute's value set to:

"[RegexPrefix:(great)]awesome[RegexSuffix:(great)]"

The new value will be "Regular expressions are awesome and you know it."