# Page History

## Key

• This line was removed.
• Formatting was changed.

...

If we want to be more specific about a range of numbers, we can put those numbers or number ranges in square brackets. For example, what if we wanted the second digit to be either a three or a four? One way would be to create two patterns (_64XX and _63XX), but a more compact method would be to do _6[docs:34]XX. This specifies that the first digit must be a six, the second digit can be either a three or a four, and that the last two digits can be anything from zero to nine.

You can also use ranges within square brackets. For example, [docs:1-468] would match a single digit from one through four or six or eight. It does not match any number from one to four hundred sixty-eight!

...

Asterisk uses a simple set of rules to determine the best match. They are:

1. Examine the first digit eliminate any patterns which don't match the first digit of the dialed number
2. Sort the remaining patterns based on the most constrained match for the current digit. By most constrained, we mean the pattern that has the fewest possible matches for this digit. As an example, the N character has 8 possible matches (two through nine), while an X has ten possible matches.
3. In the case of a match, sort the patterns in ASCII sort order. For example, _[docs:234]X and _[docs:345]X have three possible matches in the first digit, but 234 comes before 345 in ASCII sort order.
4. Move on to the next digit (moving digit by digit from left to right), and eliminate any patterns which don't match the current digit of the dialed number. Then continue back at step number two.
5. After you've examined all the digits, return the match that has been sorted to the top of the list.
1. Examine the first digit eliminate any patterns which don't match the first digit of the dialed number
2. Sort the remaining patterns based on the most constrained match for the current digit. By most constrained, we mean the pattern that has the fewest possible matches for this digit. As an example, the N character has 8 possible matches (two through nine), while an X has ten possible matches.
3. In the case of a match, sort the patterns in ASCII sort order. For example, _[234]X and _[345]X have three possible matches in the first digit, but 234 comes before 345 in ASCII sort order.
4. Move on to the next digit (moving digit by digit from left to right), and eliminate any patterns which don't match the current digit of the dialed number. Then continue back at step number two.
5. After you've examined all the digits, return the match that has been sorted to the top of the list.

Let's look at an example to better understand how this works. Let's assume Alice dials extension 6401, and she has the following patterns in her dialplan:

...

To verify that Asterisk actually does sort the extensions in the manner that we've described, add the following extensions to the [docs:users] context of your own dialplan.

...

Reload the dialplan, and then type dialplan show 6104@users at the Asterisk CLI. Asterisk will show you what would match if you were to dial extension 6104 in the [docs:users] context.

No Format
```server*CLI> dialplan show 6401@users
[ Context 'users' created by 'pbx_config' ]
'_640X' =>        1. SayAlpha(B)                                [pbx_config]
'_64XX' =>        1. SayAlpha(A)                                [pbx_config]
'_6XX1' =>        1. SayAlpha(D)                                [pbx_config]

-= 3 extensions (3 priorities) in 1 context. =-```

...