V
V
Vitaly Gusev2019-10-24 15:32:17
Asterisk
Vitaly Gusev, 2019-10-24 15:32:17

How to write a GotoIf() transition condition in Asterisk using regular expressions?

Good afternoon!
In the asterisk dial plan, you need to write a condition that redirects to one label if all conditions are met, or to another if at least one is false.
same => n,GotoIf($[$["${DSTREC}" = "0"] & $["${SRCREC}" = "0"] & $["${CIDLENGTH}" = "4"] & $[$REGEX("^SIP\/[1-9][0-9][0-9][0-9]" ${CHANNEL:0:8}) = "1"]]?recordingdisabled: recordingenabled)
There are no issues with DSTREC, SRCREC and CIDLENGTH, these values ​​are either taken from the database or formed during processing and are static, so to speak. But in that part of the channel value ($ {CHANNEL: 0: 8}), limited by me to 8 characters, the last 4 characters can change.
The first 4 characters should be equal to " SIP /", and the last 4 are only numbers, with the first of which does not go out of the range 0 - 9, and the 3 subsequent ones - from 0 to 9.
I tried to write it myself, but I feel that I got some kind of game.
Help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Drill, 2019-10-25
@guvijur

moreover, the first of which does not go out of the range 0 - 9 , and the next 3 - from 0 to 9 .

if, nevertheless, the first of which does not go out of the range 1 - 9 , then
you don’t need to do this: ${REGEX(...) = "1"}, just ${REGEX(...)}
core show function REGEX :
Return '1' on regular expression match or '0' otherwise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question