Short answer: Enter your Asterisk extensions and patterns, one per line (whole exten => lines are fine), and a dialled number. The tester shows every entry that matches, every entry that would match with more digits, and the one Asterisk picks: exact extensions first, then the most specific pattern, compared digit by digit, with . and ! last.
Built and tested in Chromium on 6 Oct 2026; runs entirely in your browser.
Table of Contents
How to use the pattern tester
- Paste the extensions of one context, for example from
extensions.conforextensions_custom.conf.same =>lines are skipped andinclude =>lines are listed separately. - Enter the number as the caller dialled it. Dashes are ignored, as Asterisk ignores them.
- Press Test number.
- Confirm on the server with
dialplan show 2125551234@from-internal(your number and context) in the Asterisk CLI.
Pattern characters
| Character | Matches |
|---|---|
_ | Starts a pattern. Without it the entry is an exact extension and X, N, Z are literal letters. |
X | Any digit 0-9. |
Z | Any digit 1-9. |
N | Any digit 2-9. |
[1237-9] | Any one character in the set; 7-9 is a range. |
. | One or more further characters. |
! | Zero or more further characters; Asterisk treats the number as complete as soon as a ! pattern matches. |
- | Ignored, except inside a [range], so _1NXX-NXX-XXXX works. |
What the output means
Asterisk picks is the winning entry. Why explains the rule that decided it. The table ranks every matching entry and shows what each position of the pattern accepts, followed by entries that need more digits and entries that do not match.
The order follows the docs.asterisk.org Pattern Matching page and the matching code in Asterisk’s main/pbx.c:
- Exact (non-pattern) extensions come before patterns.
- Patterns are compared position by position from the left. At the first position where they differ, the one that accepts fewer characters wins: a literal digit, then N (8 digits), then Z (9), then X (10). Sets in brackets count their characters; equal-sized sets are ordered by their lowest character.
.comes after any character set, and!after..- If two different sets accept the same number of characters at the same position, Asterisk goes by the order in which the extensions were loaded. The tester flags this as a tie and uses your line order.
A pattern that ends exactly where the number ends is matched before a longer one ending in !, as the matching code checks the shorter pattern first. Contexts named in include => are searched only after everything in the current context.
Examples
| Patterns | Dialled | Asterisk picks | Why |
|---|---|---|---|
_640X, _64NX, _64XX | 6421 | _64NX | _640X does not match; at the third digit N (2-9) is narrower than X (0-9). This is the example on docs.asterisk.org. |
_NXXNXXXXXX, _1NXXNXXXXXX, _011., _9X., 911, _X. | 2125551234 | _NXXNXXXXXX | N at the first digit beats X in _X.. |
| Same list | 911 | 911 | Exact extensions win; _9X. and _X. also match. |
| Same list | 9123 | _9X. | The literal 9 beats N and X at the first digit. |
_9X, _9X! | 95 | _9X | The pattern that ends with the number is found before the ! one. |
Common mistakes
- Forgetting the underscore.
NXXXXXXwithout_only matches the literal text NXXXXXX. - A catch-all that wins too often.
_X.loses to more specific patterns only when they match. Test emergency numbers like 911, 999 or 112 to be sure they reach the right extension. - Using
.where a fixed length is meant._9.matches 9 followed by anything, so the call can be sent before the caller finishes dialling. Prefer explicit lengths such as_9NXXXXXX. - Expecting
.to match nothing. It needs at least one more character; use!for zero or more. - Looking in the wrong context. The phone’s context (set on its PJSIP endpoint) decides where matching starts; included contexts come after.
Official documentation: docs.asterisk.org: Pattern Matching · Asterisk source: main/pbx.c
Related: Install Asterisk 22 LTS on Debian 13: Step-by-Step Guide · SIP Response Codes: Lookup for Every SIP Error, With Causes and Fixes · Troubleshoot SIP Calls with sngrep and the Asterisk PJSIP Logger · fail2ban for Asterisk and FreePBX: Block SIP Password Guessing · SIP Trace Analyzer: Find NAT, Codec and Dropped-Call Problems in a SIP Log
See also: Asterisk Dialplan Pattern Matching: X, N, Z, [ ], . and ! Explained
Frequently asked questions
How does Asterisk choose between two matching patterns?
Exact extensions first. Otherwise it compares the patterns from the left and, at the first position where they differ, picks the one that accepts fewer characters there. . and ! come last.
What is the difference between . and ! in an Asterisk pattern?
. matches one or more further characters. ! matches zero or more, and Asterisk treats the number as complete as soon as a ! pattern matches.
What do X, Z and N mean?
X is any digit 0-9, Z is 1-9 and N is 2-9. They only have this meaning in patterns that start with an underscore.
Are dashes allowed in patterns?
Yes. Asterisk ignores dashes in extensions and patterns, except inside a bracketed range, so _1NXX-NXX-XXXX is the same as _1NXXNXXXXXX.
How do I check which extension matches on my server?
Run dialplan show NUMBER@CONTEXT in the Asterisk CLI. It lists the extensions in that context that match the number.