Why does this regex not match my SIP header?


Hello all,
I am working with Asterisk 1.8 and need to get extension numbers out of SIP headers. For this, I use the following regex construct in my dialplan:

same => n,Set(regx="([0-9]+)")
same => n,Set(ZIEL=$["${VAR}" : ${regx}])

I have to examples for the variable VAR:
1.: sip:3112;phone-context=hallo@;user=phone
2.: tel:3311;reason=no-answer;counter=1;screen=no;privacy=off

The first one is the SIP header “To”, for this, the dialplan works fine.
The second one is the SIP diversion header (Asterisk is not able to parse this because 1.8 does not know about tel: URIs). It does not work, which means, VAR is empty.

I ask myself: why? There are no additional characters in the second one.
Apart from that: is there any further documentation about how and using what syntax, regex “grepping” in Asterisk is supported?


Here is an example of how I use the REGEX function, I’m testing the To header to see if the string intercom=true is present:

ExecIf($[${REGEX("intercom=true",${SIP_HEADER(To)})} = 0]?SIPAddHeader(Alert-Info: InternalRing))


Thanks for your answer. Please note the difference: you are doing a regex check using the REGEX function, where the result is 1 or 0 if the variable matches regex or not.
What I want is getting the matched part of the variable.


I don’t believe there is a dialplan function that does what you want, the : operator is also a test not an assignment.


As I wrote, I actually currently use this. Look also here: https://www.voip-info.org/asterisk-expressions/#Regularexpressions