Use normalized P-Preferred-Identity as CALLERID

Hi!

I would like to normalize the number in P-Preferred-Identity and then set it as CALLERID(num).

exten => _.,4,Set(PPISIPURI=${PJSIP_HEADER(read,P-preferred-identity):5})
(I know “_.” is bad, on my TODO)

P-Preferred-Identity holds something like this:
<sip:0123456789@8.8.8.8>

What I need is 0123456789, which can also be +1123456789 (wich then results in bad numbers because of the -5 “cut”).

Kind regards
Kevin

How can I get the first match of pattern matching?

NoOp(${REGEX("\+?[0-9]+" ${PJSIP_HEADER(read,P-preferred-identity)})})

This only returns true or false, not the match.

Use the “:” operator, instead. https://wiki.asterisk.org/wiki/display/AST/Operators

I tried it:

The regular expression is anchored to the beginning of the string with an implicit `^`

My regex matches strings somewhere in the string, not necessarily at the beginning (^):

\+?[0-9]+
exten => _.,5,Set(regex="\+?[0-9]+")
exten => _.,6,Set(CIDFROMPPI=$["${PPISIPURI}" : ${regex}])

Also not working (match is garbage):

exten => _.,5,Set(regex="\+?[0-9]+")
exten => _.,6,Set(CIDFROMPPI=$["${PPISIPURI}" =~ ${regex}])
  1. You haven’t delimited the required sub-string.

  2. the reason anchoring at the beginning is sufficient is that you can use standard regular expression features to make it equivalent to an un-anchored one, given that you need to do (1).

1 Like

Ok, thanks, found the correct expression:
(\+?[0-9]+)

This time it works!
Thanks!

1 Like