System information
And finally this one:
_011.
Note the period on the end. This pattern matches any number that starts with 011 and
has at least one more digit. In the NANP, this indicates an international phone number.
(We’ll be using these patterns in the next section to add outbound dialing capabilities
to our dialplan.)
Pattern Matches in Other Countries
The examples in this section were NANPA-centric, but the basic logic applies in any
country. Here are some examples for other countries (note that we were not able to test
these, and they are almost certainly incomplete):
; UK, Germany, Italy, China, etc.
_00. ; international dialing code
_0. ; national dialing prefix
; Australia
_0011. ; international dialing code
_0. ; national dialing prefix
This is by no means comprehensive, but it should give you a general idea of the patterns
you’ll want to consider for your own country.
Using the ${EXTEN} channel variable
So what happens if you want to use pattern matching but need to know which digits
were actually dialed? Enter the ${EXTEN} channel variable. Whenever you dial an ex-
tension, Asterisk sets the ${EXTEN} channel variable to the digits that were dialed. We
can use an application called SayDigits() to test this out:
exten => _XXX,1,Answer()
same => n,SayDigits(${EXTEN})
In this example, the SayDigits() application will read back to you the three-digit ex-
tension you dialed.
Often, it’s useful to manipulate the ${EXTEN} by stripping a certain number of digits off
the front of the extension. This is accomplished by using the syntax ${EXTEN:x}, where
x is where you want the returned string to start, from left to right. For example, if the
value of ${EXTEN} is 95551212, ${EXTEN:1} equals 5551212. Let’s try another example:
exten => _XXX,1,Answer()
same => n,SayDigits(${EXTEN:1})
In this example, the SayDigits() application would start at the second digit, and thus
read back only the last two digits of the dialed extension.
128 | Chapter 6: Dialplan Basics