Difference between revisions of "Misc. Dialplan Tools regex"

From FreeSWITCH Wiki
Jump to: navigation, search
(See Also)
m (Moved links to the right places.)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Description==
 
==Description==
Execute Regular Expression<br/>
+
 
 +
Executes a [[Regular Expression]].
 +
 
 
'''NOTE''': 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.
 
'''NOTE''': 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.
  
Line 6: Line 8:
 
  regex value expression results*
 
  regex value expression results*
  
( results is opitional, without this argument the regex returns true or false )
+
(results is optional, without this argument the regex returns true or false)
  
you can test your dialplan on the FS console like this
+
You can test your dialplan on the FS console like this.
  
 
<pre>
 
<pre>
 
regex 61555555555|^61([0-9]{9})$|0%1  
 
regex 61555555555|^61([0-9]{9})$|0%1  
 
</pre>
 
</pre>
this would return 0555555555
+
 
 +
This would return 0555555555.
  
 
<pre>
 
<pre>
 
regex 61555555555|^61([0-9]{9})$
 
regex 61555555555|^61([0-9]{9})$
 
</pre>
 
</pre>
this would return true
+
 
 +
This would return true.
  
 
==Parameters==
 
==Parameters==
 +
 
* value = string to run regex against
 
* value = string to run regex against
 
* expression = the actual regular expression
 
* expression = the actual regular expression
 
* results = result handling string ( optional. without the regex returns true / false )
 
* 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.
+
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.
+
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.
 +
 
 +
<pre>
 +
regex 9999|^(1234\|9999)$
 +
</pre>
 +
 
 +
This would return true.
  
 
==Examples==
 
==Examples==
  
modify an Australian E164 caller_id to 0NSN format
+
Modify an Australian E164 caller_id to 0NSN format.
 +
 
 
<pre>
 
<pre>
 
<action application="set" data="effective_caller_id_number=${regex(${caller_id_number}|^61([0-9]{9})$|0%1)}"/>
 
<action application="set" data="effective_caller_id_number=${regex(${caller_id_number}|^61([0-9]{9})$|0%1)}"/>
Line 37: Line 51:
  
 
==See Also==
 
==See Also==
 +
 
* [[Dialplan]]
 
* [[Dialplan]]
* [[Mod_commands|API Commands]]
+
* [[Mod_commands#regex]]
 +
* [[Regular Expression]]
 +
 
  
 
[[Category:Dialplan]]
 
[[Category:Dialplan]]
 +
[[Category:Configuration]]
 +
[[Category:Modules]]
 
[[Category:dptools]]
 
[[Category:dptools]]

Latest revision as of 21:52, 9 October 2013

Contents

Description

Executes a Regular Expression.

NOTE: 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