Pattern-matching option for leading 1 on Inbound Route?

I’ve done a lot with FreePBX over the years and I’m probably just missing something obvious here – but is there a pattern-matching character that means something like “0 or 1 digits”? Basically, I sometimes have multiple SIP providers via trunks – Twilio, Flowroute, Telnyx. For Inbound Routes, Twilio does not send a leading 1 for the DID, but FlowRoute does. I’m trying to make a DID pattern-match that works for both and can’t seem to do it.

So, for example, my Inbound Route DID for Twilio might look like this:


But if that comes from FlowRoute, it would need to be this:


Can I do something to mean “1 or nothing” for that first digit so that I have one pattern that would match both 6165551111 and 16165551111?

I know that “!” can represent zero characters in some circumstances. Would this work?


Or maybe this:


Or is there just a better way to do this? Thanks!

Asterisk dialplan patterns only allow wildcards at the end of the number

The best solution is probably to define custom dialplan that canonicalises the numbers before going to from-pstn. Although it doesn’t cover your specific case, the built-in special context from-pstn-e164-us demonstrates the general principles of how to do this.

1 Like

Ok, thanks for the info. I think the best solution for me – because I want to keep it simple and very visible in the Inbound Routes list – is to simply add a 2nd Inbound Route for each option. So identical Inbound Routes, but one with and one without the leading 1. Just keeps it cleaner, I think.

You could strip off the leading 1 (if it exists) with:


He wants to do this on ${EXTEN}, not the caller ID! The nearest equivalent on ${EXTEN} would result in a loop!

Just an example. Can be used quite effectively.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.