# Best way to match (xxx) xxx-xxxx

Hello dear group,

What would be the best way to match (xxx)xxx-xxxx ?

Also, can we actually use the ()'s as I didn’t see it in the doc. The following however seems to work when I dial but I am pretty sure I am messing up something as I read somewhere that nothing is taken into account after the dot:

exten => _(NXX).NXX-XXXX,1,Set(rewrite=\${EXTEN:1:3}\${EXTEN:6:3}\${EXTEN:10:4})
exten => _(NXX).NXX-XXXX,2,Goto(nanpa,\${rewrite},1)

Also, how would I put an optional +1 at the front, such as: +1(xxx)xxx-xxxx

Just want to make sure it does it the way I mean it.

Thank you !

“-” is ignored during pattern matching. I’m not sure about “()”.

To match with and without +!, either match the +1 and transform the number, or use two dialplan lines with the same actions and priorities (you can use s or n-1 to repeat a priority).

Thanks, I think my approach wasn’t good enough to start with so I used the filter function:

exten => _1(NXX).,1,Set(foo=\${FILTER(0123456789,\${EXTEN:1})})
exten => _1(NXX).,n,GotoIf(LEN("\${foo}") = 10?\${foo},1)
exten => _1(NXX).,n,Hangup
exten => _[+]1.,1,Set(foo=\${FILTER(0123456789,\${EXTEN:2})})
exten => _[+]1.,n,Goto(LEN("\${foo}") = 10?\${foo},1)
exten => _[+]1.,n,Hangup
exten => _(NXX).,1,Set(foo=\${FILTER(0123456789,\${EXTEN})})
exten => _(NXX).,n,GotoIf(LEN("\${foo}") = 10?\${foo},1)
exten => _(NXX).,n,Hangup