Emergency server help: get in touch

Asterisk Dialplan Pattern Tester: Which Extension Matches?

Test Asterisk extension patterns against a dialled number and see which one Asterisk picks, with the X, Z, N, [ ], . and ! rules explained.

Last updated
October 6, 2026

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.

How to use the pattern tester

  1. Paste the extensions of one context, for example from extensions.conf or extensions_custom.conf. same => lines are skipped and include => lines are listed separately.
  2. Enter the number as the caller dialled it. Dashes are ignored, as Asterisk ignores them.
  3. Press Test number.
  4. Confirm on the server with dialplan show 2125551234@from-internal (your number and context) in the Asterisk CLI.

Pattern characters

CharacterMatches
_Starts a pattern. Without it the entry is an exact extension and X, N, Z are literal letters.
XAny digit 0-9.
ZAny digit 1-9.
NAny 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:

  1. Exact (non-pattern) extensions come before patterns.
  2. 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.
  3. . comes after any character set, and ! after ..
  4. 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

PatternsDialledAsterisk picksWhy
_640X, _64NX, _64XX6421_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_NXXNXXXXXXN at the first digit beats X in _X..
Same list911911Exact extensions win; _9X. and _X. also match.
Same list9123_9X.The literal 9 beats N and X at the first digit.
_9X, _9X!95_9XThe pattern that ends with the number is found before the ! one.

Common mistakes

  • Forgetting the underscore. NXXXXXX without _ 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.

Free website test

Is your website set up right?

Check SSL, security headers, redirects, robots.txt, sitemap, llms.txt and security.txt in one test. It takes about 30 seconds.