Skip to main content

mod_dptools: regex

About

Executes a Regular Expression.

Technically this is not a dialplan application but rather an API. API's are normally done at the CLI, however using the ${my_api(my_args)} syntax with the ''set'' application allows for the use of many API's inside the dialplan itself.

Usage

regex value expression results*

(results is optional, without this argument the regex returns true or false)

You can test your dialplan on the FS console like this.

regex 61555555555|^61([0-9]{9})$|0%1 

This would return 0555555555.

regex 61555555555|^61([0-9]{9})$

This would return true.

Parameters

  • value = string to run regex against
  • expression = the actual regular expression
  • results = result handling string ( optional. without the regex returns true / false )

In your results string, you can not use $0 $1 $2 $3 as you normally would, as they would contain the results of your "condition" expression.

So inline Regex's use %0 %1 %2 %3 as their format.

If you want to use pipes as an logical OR in regular expressions you must escape them, because the regex command already uses pipes to separate parameters.

regex 9999|^(1234\|9999)$

This would return true.

Examples

Modify an Australian E164 caller_id to 0NSN format.

<action application="set" data="effective_caller_id_number=${regex(${caller_id_number}|^61([0-9]{9})$|0%1)}"/>

See Also