[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)

Jonathan H lardconcepts at gmail.com
Thu Oct 13 05:54:52 CDT 2016


Back to basics here. I want to match on one OR two digits.

The following two both work, but ONLY for more than one digit, which
is not as expected from the docs (see below).

exten => _X.,1,SayNumber(${EXTEN})
exten => _[0-9].,1,SayNumber(${EXTEN})


This next one will ONLY match 2 digits, as expected, but the first two
SHOULD match one or more, right?

exten => _XX,1,SayNumber(${EXTEN})

The following pattern works, but I thought it was "dangerous" and to
be discouraged?
exten => _.,1,SayNumber(${EXTEN})

So, again, if someone dials 1 and a one second delay passes, I want it to say 1.
If someone dials 1 then another 1 within a second then I want it to be
11, and 111 should be invalid.

(I've Set(TIMEOUT(digit)=1) )

Yes, I can do this with multiple lines, but the docs suggest this
should be easily do-able in 1 line, and I don't want to double the
amount of dialplan (there'll be a few of these!).

Here are my references:

---------------------------------------------------

https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching

The letter X or x represents a single digit from 0 to 9.
The period character (.) at the end of a pattern matches one or more
remaining characters. You put it at the end of a pattern when you want
to match extensions of an indeterminate length.

---------------------------------------------------

Page 141 of the Asterisk Definitive Guide 4th Edition:

. (period)
Wildcard match; matches one or more characters, no matter what they are.
If you’re not careful, wildcard matches can make your dialplans do
things you’re not expecting (like matching built-in extensions such
as i or h). You should use the wildcard match in a pattern only after
you’ve matched as many other digits as possible. For example, the
following pattern match should probably never be used:
_.
In fact, Asterisk will warn you if you try to use it. Instead, if you
really need a catchall pattern match, use this one to match all strings
that start with a digit followed by one or more characters (see ! if
you want to be able to match on zero or more characters):
_X.
Or this one, to match any alphanumeric string:
_[0-9a-zA-Z].

---------------------------------------------------

http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns
Do not use a pattern of _. as this will match everything including
Asterisk special extensions like i, t, h, etc. Instead use something
like _X. or _X which will not match __special__ extensions..
So what do you use instead of _. ? Many examples use this construct,
but if you use it you may see a warning message in the log advising
you to change _. to _X.

---------------------------------------------------



More information about the asterisk-users mailing list