Remove digits from the end of a dial pattern


I’ve just hooked up an freepbx system up to an old definity G3 V6 system, and incoming and outgoing calls are working fine. The asterisk system has 3 IAX2 trunks to other asterisk boxes, all which work just fine by sending 4 digit extension codes. What I’m trying to get working is to have the definity send a 4 digit code, asterisk passes it out the IAX trunks appropriately.

Unfortunately, for reasons beyond my ability to understand, whenever the definity sends any code less than 7 digits, it appends a # to the end of the code. So when a user dials 4567, asterisk receives 4567#.

Is there a way to have asterisk remove the # at the end of the pattern? I know using a | removes digits from the beginning of the pattern.

My current pattern is XXXX#
I’d like it to replace that pattern with XXXX


Use the pattern xxxx|#

The only thing I am not sure about is the #

How are the calls coming into your system from the G3 system - are they arriving on a trunk or what?

If they are coming in on a trunk, then in etc/asterisk/extensions_custom.conf you could put a piece of code that looks like this:

exten => _XXXX#,1,Goto(from-trunk,${EXTEN:0:4},1)
exten => _X!,1,Goto(from-trunk,${EXTEN},1)
exten => h,1,Macro(hangupcall,)

Then in your trunk configuration (the trunk that the G3 calls come in on) change context=from-trunk to context=custom-strip-pound. If my code is correct, it should pass only the first four characters of calls coming in as XXXX# (and leave any other pattern unchanged) to from-trunk.

Note you could do something similar on the outgoing side - route your calls to a custom trunk that jumps to a custom context that strips the #, then sends the call back to outbound-allroutes - but it’s probably a lot easier to catch it on the incoming call to the FreePBX box and nip the problem in the bud there, so to speak.