[asterisk-users] Realtime extensions
Jared Smith
jsmith at digium.com
Mon Jun 22 13:05:19 CDT 2009
On Mon, 2009-06-22 at 12:30 -0500, Danny Nicholas wrote:
> Hey Jared, Do you have a FAQ reference for some commonly asked questions
> like this? I've got an email archive that goes back almost a year, but
> finding a reference in 4K+ emails is sometimes difficult, even if I can
> remember some keyword to help out.
I wish I did... the only thing I really have is my brain. When
searching mailing list archives, I tend to use www.markmail.org, but I
did a quick search and didn't find the post I was looking for, so I'll
re-iterate my understanding of the pattern matching here for posterity's
sake:
Pattern Matching: Asterisk searches the extensions and patterns digit by
digit, from left to right, and applies the following three rules:
Rule 1) For the current digit, order the possible matching extensions
based on the most constrained match. For example, let's say Asterisk
was looking at the first second digit in this context, and the caller
dialed extension 123:
[pattern-test]
exten => _1XX,1,NoOp(Option 1)
exten => _1[2-4]X,1,NoOp(Option 2)
exten => _1NX,1,NoOp(Option 3)
In this example, the second option would be given priority over options
one or three, as there are only three possible matches for this digit
(2, 3, or 4), while the other options have more possibilities (8 in the
case of the N, or 10 in the case of the X).
Rule 2) In the case of a tie (when the number of possibilities for this
digit) is the same between two extensions, the extensions are then
sorted into ASCII sort order. Consider this context for a moment:
[pattern-test-two]
exten => _1[1-8]X,1,NoOp(Option 4)
exten => _1NX,1,NoOp(Option 5)
In this example, the second digit has eight possibilities in both
extensions... so the extensions will be sorted in ASCII sort order. The
1 comes before the N in the ASCII table, so option 4 will be selected
before option 5.
Rule 3) If the dialed digit can't match a particular pattern, exclude
the pattern from the list of matches. This means that if a pattern was
more constrained in earlier matches and therefore at the top of the list
of matching extensions, later digits can disqualify it. To illustrate
this point, let's look at the following example:
[pattern-test-three]
exten => 1[2-4]N,1,NoOp(Option 6)
exten => 1NX,1,NoOp(Option 7)
In this case, let's assume the caller dialed extension 130. After the
first digit, the two patterns are tied. After the second digit, option
6 gets sorted above option 7 because it is more constrained. After the
third digit, however, option 6 is eliminated because the last digit
can't be a zero. That means that Option 7 will match.
Clear as mud?
--
Jared Smith
Training Manager
Digium, Inc.
More information about the asterisk-users
mailing list