The general advice is that you should canonicalise numbers. However I can only find suggestions of how to do this with custom dialplan, but they are very old, so I may have missed a more GUI oriented, more recent, way of doing this.
However, it looks as though no-one was suggesting alternatives to custom dialplan as recently as 2019:
. is only recognized as the last character. I believe this limitation exists to allow patterns to be matched with a minimum of backtracking, which is important because every dialplan line has to be pattern matched at run time.
thats where i get caught up.
I have trunks and DIDs from 4 different carriers (don’t ask…) and depending on which number was dialed, and what their origin country was, the same caller can come in 3 different ways.
I just want a straightforward way to route every call from bob to an inbound queue no matter which of our numbers they call.
The underlying pattern matching is done by Asterisk, and is optimised for directly working with dialplans. When doing that, it only takes a small number of extra lines of code to canonicalise numbers, compared with the over 100 that FreePBX uses when processing a typical call.
The from-pstn-e164-us context will handle 2/3 of your DID patterns. Maybe copy it and add your third one (1NXXNXXXXXX) and send inbound calls to your custom context. Then use just the 10-digit pattern in your inbound routes.
So as you’ve learned the dial patterns in inbound routes and elsewhere in FreePBX are not regex’s. Patterns can contain digits, * ,# ,N, Z, X and a few other chars. The ! and . are only meaningful as the final character of a pattern.
If the CID/DID format changes depending on provider, one thing you can do in Can/US is to set all your trunks to use context from-pstn-e164-us which will normalize inbound CID/DID to 10 digits. On existing systems that may mean touching all your routes tho, so you may want to write your own context to only touch the things you want. Once CID/DID is normalized, then a single inbound route with a single CID match pattern will work for all providers.
Asterisk has two ways in which patterns can be invoked. One is the core dialplan interpreter, which is where the _ prefix patterns come from. That does not support a ? operator, but the patterns are precompiled, to allow a parallel search of all the patterns. The other is a standard posix style regular expression, which is invoked via functions and expressions. That has to be compiled every time, doesn’t result in one of several patterns being recognized, and can involve, expensive, back tracking. That does support ? operators.
Anywhere in FreePBX that accepts a plain number or a pattern starting with _ is using the first mechanism, internally.