Optional First Digit in Dial Patterns

Hi I have two outbound dial patterns given bellow. If any user dials 01234 the calls will be placed in the trunk directly but if any user forgot to add 0 before the number then asterisk will add zero before the number.

1st One

exten => _0XXXX,1,Dial(SIP/trunk_name/${EXTEN})
same => n,Hangup

2nd One

exten => _XXXX,1,Dial(SIP/trunk_name/0${EXTEN})
same => n,Hangup

I want to combine these two dial patterns into one. Is it possible to make the 1st digit optional??

Not directly. If you can explain why it is a real problem for you, we may be able to suggest solutions to your specific problem, e.g. rewriting with Goto, more complex text processing on the right hand side, or using multiple patterns on the same priority.

How about something like:

exten = _0., 1, goto(${CONTEXT}, ${EXTEN:1}, 1)

Untested, but hopefully you get my drift.

That is missing two $s or you failed to mark it as pre-formatted text. It is an example of what I called “rewriting with Goto”.

(Marked extensions.conf snippet above as preformatted to retain dollar signs.)