Pattern matching in Dial Plan

Hi All,

I am facing a problem regarding dial plan of Asterisk. Currently, my dial plan inside a context is –

exten => 43148161/09818123456, 1, dial(dahdi/1/009999790061)

it means, if caller (09818123456) call 43148161 then asterisk forward it to 009999790061. And for your information it is working fine. The problem is, if CID number is come like 919818123456 instead of 09818123456, it means prefix is changed; then our dial will not work.

I think, for solving this problem, I should used regular expression so that only match the last 10 digits and ignore prefix (it can be single zero ‘0’ or ‘91’, like in our case). But I don’t know the implementation of this solution.

So, please suggest me that how should I implement it or other solution, if exist of this problem.

Regards,
Amit Saini

Asterisk REs cannot have optional leading symbols. You will need two seaprate entries.

david55, please explain, what you want to say?

You cannot do what you want to do. You must include the number both with and without the initial 9. Asterisk regular expressions are not sufficienty powerful.

thanks david55, for your reply. But If I used Pattern-matching in place of Regular expression then will it be helpful?

“Pattern matching” is a regular expression system.

I rather new to the Asterisk world, but I’m no stranger to VoIP systems (Cisco, Nortel, etc)
I was looking at the Asterisk pattern matching, and it look suspiciously much like Regex.

I was considering trying something like this, from the RegEx world:
Prefix 9[1]?(?:345)?
Match Pattern 322XXXX

This would allow for:
91 345-322-1234 -> send to local trunk 322-1234
9 345-322-1234 -> send to local trunk 322-1234
9 322-1234 -> send to local trunk 322-1234

Is this level of complexity supported in Asterisk dial plan/patterns?

Thanks for any insight that can be provided.

Pattern matching[1] is not regular expression. The given configuration would not work.

[1] https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching

You may want to look at the REGEX() function or the agi() application.

Since you can write an AGI in the language of your choice, you can ‘regex’ to your hearts content and set CONTEXT, EXTENSION, and PRIORITY as desired. Or, (and probably a more maintainable avenue) set a channel variable and use the gotoif() application in your dialplan.

Just a suggestion…

Rather than adding to an eleven year old topic tangentially, feel free to start a new topic :slight_smile:

I appreciate the response, and especially the clarification.
I just wanted to check, before plunking in a bunch of exotic dial plan patterns.
While researching the matter, I ran across some things that insinuated the Asterisk pattern matching was essential the same as regular expressions.
Based on the similarities, I was hopeful, but I had my suspicions the Asterisk patterns aren’t.
I will investigate the REGEX and agi functions, and post a new thread accordingly, if I have questions.
For what is worth, if there was a RegEx option flag, for Dial Plans, that would be sweet.
Thanks!