Manipulating numbers for Dial pattern

Hello Asterisk Community.

I am wonder what is the best way to manipulate ${EXTEN} number and make an custom number in order to dial out.

Example.

if I dial out from my extension an Argentinian number 5491155667799 at the time to send the call I need to remove 549, them add 15 + rest of the number. So the resulting number is 15 55667799 but that is only for 54911 Buenos aires area code.

Another example:

There is another area codes:
388, 3884, 3885, 3886, 3887

if the number is 549388XXXXXXX I need to strip it as: 0 388 15 XXXXXXX
but if the number is 5493884XXXXXX I need to strip it as 0 3884 15 XXXXXX

I don’t know if in my extension.conf I need to use Gotoif, or other best application in order to do this.

I will be very thanks full if you may provide me any idea how to resolve this complicate algorithm.

Thank You from Now.
Abel

Is there a list of dialing rules you can provide for your situation?

You can use the Regex function search for matches in strings: https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_REGEX

But you will need to use it with an ExecIf or a GotoIf statement to apply the logic.

This looks like exactly the case that dialplan _ type expressions are intended to deal with, e.g.

exten => _549388X.,n,Goto(038815${EXTEN:6},1)
exten => _5493884.,s,Goto(0388415${EXTEN:7},1)

You can add more X’s in the pattern if you want to make sure matching numbers are a certain minimum length. Miss the . if you want to match an exact length.