Dial Pattern Optional Number

Dear folks,

I have a question about dial patterns.

Essentially I wish to match a number followed by one or two optional digits.

I.e. For example, I wish to match 123456 and 1234567 and 12345617 in a single pattern.

Is it possible to make a number optional?

I’ve checked here: http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns

and I found the exclamation character may do what I want, but I can’t seem to get it to work with this:

123456X!X!

I’m sure this has been done before, but maybe you could bestow some wisdom upon me why this doesn’t work the way I want to.

Also, would it be possible to match an optional character in between?
I.e. 123n456 would match 1230456 and 123456?

Thank you all in advance for your great help!

Hi there, where and how are you using these?

My understanding is that you can only really match based on the start of a dial string. So to achieve your result of 123456, 1234567, 12345617 you could use
123456!

which basically means match anything that is 123456, or that starts with 123456. Unfortunately that also matches things like 12345623423543534.
The other alternative would be to just have multiple patterns for a route (I assume this is for an outbound route). ie
123456
123456X
123456XX

If you were really adventurous you could create a custom dialplan in extensions_custom.conf and set it up to put additional checks within the actual dialplan logic to do further limitations on it… but that’s quite a bit more complicated.

Same logic would apply for the “optional” digit.

Thanks,

-Rob

Thank you for your swift reply!

The reason I need this because we need to match outbound numbers to a trunk that are 9-12 digits long (the phone numbers supposed to go out the trunk have a variable length).

I understand there is no wildcard match for a single character, is this correct?

Oh ok, wildcards are supported…
e.g.
X <-any digits 0-9
Z <-any digits 1-9
N <-any digits 2-9
! <-anything, including non-digits
. <-accept anything after, e.g. 123. meaning 123456, 12345…

Thanks again!

I know about those, I meant a wildcard matching a single character (i.e. non-greedy).

Essentially equivalents for regex "{1}"
The dot is more like a regex “+”

Coming to think of it, why wouldn’t asterisk support regex matches anyways? That would allow for a lot more complicated patterns.

Asterisk does support regular expressions in dial plan, but FreePBX does not (or at least not fully, ymmv). If you are manually coding the plan you can read up on the regex function:
https://wiki.asterisk.org/wiki/display/AST/Function_REGEX
http://www.voip-info.org/wiki/view/Asterisk+func+regex