Zum Hauptinhalt springen

Dialplan & Trunk Regex

Dialplan Regex examples

tip

For star codes to work in the dial plan, you must configure Star codes that are handled in dial plan. For e.g. set to *67* to allow calls like *6723232323, *67232323232323, etc.

PatternReplacementExample InputExample OutputDescription
\*67([0-9]{6})(@.*)\*67\1\2*67112233*67112233Caller ID blocking: Preserves *67 prefix with 6-digit number
\#5(011[0-9]{6,20})(@.*)\1\2#501133445566770113344556677International dialing shortcut: Removes #5 prefix, keeps international number
^0(9[0-9]{7})(@.*)+64\1\2093445565+6493445565New Zealand national to international: Converts 0 prefix to +64 country code

Pattern Explanation

  • \*67([0-9]{6})(@.*): Matches "*67" followed by exactly 6 digits, captures the digits and any following context
  • \#5(011[0-9]{6,20})(@.*): Matches "#5011" followed by 6-20 additional digits, captures the international number and context
  • ^0(9[0-9]{7})(@.*): Matches line starting with "0" followed by "9" and exactly 7 more digits, captures the national number and context

Replacement Explanation

  • \*67\1\2: Keeps the "*67" prefix, followed by captured digits (\1) and context (\2)
  • \1\2: Returns only the captured international number (\1) and context (\2), removing the "#5" shortcut
  • +64\1\2: Replaces the "0" with "+64" country code, followed by the captured number (\1) and context (\2)

Trunk Regex Examples

You can use a list of regex expressions to route incoming calls. Below is an example with two separate conditions using space as the delimiter:

!^1?([0-9]{9})$!61\1!t!123! !^0?([0-9]{9})$!61\1!t!123!

Regex Pattern Breakdown

PatternReceived NumberFinal Number SearchedDescription
!^1?([0-9]{9})$!61\1!t!123!1300300300611300300300Matches optional "1" prefix + 9 digits, replaces with "61" + captured digits
!^0?([0-9]{9})$!61\1!t!123!023344556661233445566Matches optional "0" prefix + 9 digits, replaces with "61" + captured digits

How It Works

First regex pattern: When a number like 1300300300 is sent to the PBX (or when formatting is enabled for specific Caller ID display that also formats the destination number), the first regex pattern will replace it with 611300300300.

Second regex pattern: When a number like 0233445566 is sent to the PBX (or when formatting is enabled for specific Caller ID display that also formats the destination number), the second regex pattern will replace it with 61233445566.