Hello, I have the following pcre regex method call: pcre_match("$hdr(From)", "(?i)^(restricted|anonymous|private|unknown|unavailable)") to match calls that are sent without a proper ANI in a case-insensitive manner, however it does not seem to return true for the following example From Header:
From Header: "Unavailable"
<sip:Restricted@192.168.47.68sip%3ARestricted@192.168.47.68
;tag=gK07327e23
Any thoughts / input is appreciated, and as always thank you for your help!
Sincerely, Brandon Armstead
Hello, Just realized the " and the ^ is probably why it is not matching -- total oversight. Thanks guys!
Sincerely, Brandon Armstead
On Thu, Sep 17, 2009 at 4:55 PM, Brandon Armstead brandon@cryy.com wrote:
Hello, I have the following pcre regex method call: pcre_match("$hdr(From)", "(?i)^(restricted|anonymous|private|unknown|unavailable)") to match calls that are sent without a proper ANI in a case-insensitive manner, however it does not seem to return true for the following example From Header:
From Header: "Unavailable" <sip:Restricted@192.168.47.68sip%3ARestricted@192.168.47.68
;tag=gK07327e23
Any thoughts / input is appreciated, and as always thank you for your help!
Sincerely, Brandon Armstead
El Viernes, 18 de Septiembre de 2009, Brandon Armstead escribió:
Hello, I have the following pcre regex method call:
pcre_match("$hdr(From)", "(?i)^(restricted|anonymous|private|unknown|
unavailable)")
to match calls that are sent without a proper ANI in a case-insensitive manner, however it does not seem to return true for the following example From Header:
From Header: "Unavailable" <sip:Restricted@192.168.47.68sip%3ARestricted@192.168.47.68
;tag=gK07327e23
Any thoughts / input is appreciated, and as always thank you for your help!
You are using ^ symbol which means that the string MUST START by: restricted|anonymous|private|unknown|unavailable
But your string $hdr("From") starts by "Unavailable" (*including* the quotation marks so it doesn't match).
If the From URI username is enough (Restricted) you could do:
pcre_match("$dU", "(?i)^(restricted|anonymous|private|unknown| unavailable)")
If you need to match the Display-Name ("Unavailable") then you must add the quotation marks to the regular expression:
pcre_match("$fn", "(?i)^(")?(restricted|anonymous|private|unknown| unavailable)(")?")
Note that I use $fn rather than $hdr("From"), being $fn the From Display-Name: http://kamailio.org/dokuwiki/doku.php/pseudovariables:1.5.x#from_display_nam...
El Viernes, 18 de Septiembre de 2009, Iñaki Baz Castillo escribió:
El Viernes, 18 de Septiembre de 2009, Brandon Armstead escribió:
Hello, I have the following pcre regex method call:
pcre_match("$hdr(From)", "(?i)^(restricted|anonymous|private|unknown|
unavailable)")
to match calls that are sent without a proper ANI in a case-insensitive manner, however it does not seem to return true for the following example From Header:
From Header: "Unavailable" <sip:Restricted@192.168.47.68sip%3ARestricted@192.168.47.68
;tag=gK07327e23
Any thoughts / input is appreciated, and as always thank you for your help!
You are using ^ symbol which means that the string MUST START by: restricted|anonymous|private|unknown|unavailable
But your string $hdr("From") starts by "Unavailable" (*including* the quotation marks so it doesn't match).
If the From URI username is enough (Restricted) you could do:
pcre_match("$dU", "(?i)^(restricted|anonymous|private|unknown| unavailable)")
If you need to match the Display-Name ("Unavailable") then you must add the quotation marks to the regular expression:
pcre_match("$fn", "(?i)^(")?(restricted|anonymous|private|unknown| unavailable)(")?")
Note that I use $fn rather than $hdr("From"), being $fn the From Display-Name: http://kamailio.org/dokuwiki/doku.php/pseudovariables:1.5.x#from_display_n ame
Also, it's better if you use =~ instead of pcre_match since =~ compiles the regular expression during script file initial parsing. 'regex' module is useful if you use the pcre_match_group() function (which matches against the content of a file separated by sections).
Hello, I do not know why it did not dawn upon me to simply use the =~ operator. However it does appear to error out / not compile:
"(?i)(restricted|anonymous|private|unknown|unavailable)", i.e.
produces a runtime error:
if($hdr(From) =~ "(?i)(restricted|anonymous|private|unknown|unavailable)"){
}
* sending this to list.
On Thu, Sep 17, 2009 at 5:05 PM, Iñaki Baz Castillo ibc@aliax.net wrote:
El Viernes, 18 de Septiembre de 2009, Brandon Armstead escribió:
Hello, I have the following pcre regex method call:
pcre_match("$hdr(From)", "(?i)^(restricted|anonymous|private|unknown|
unavailable)")
to match calls that are sent without a proper ANI in a case-insensitive manner, however it does not seem to return true for the following example From Header:
From Header: "Unavailable" <sip:Restricted@192.168.47.68 sip%3ARestricted@192.168.47.68<
sip%3ARestricted@192.168.47.68 sip%253ARestricted@192.168.47.68>
;tag=gK07327e23
Any thoughts / input is appreciated, and as always thank you for your
help!
You are using ^ symbol which means that the string MUST START by: restricted|anonymous|private|unknown|unavailable
But your string $hdr("From") starts by "Unavailable" (*including* the quotation marks so it doesn't match).
If the From URI username is enough (Restricted) you could do:
pcre_match("$dU", "(?i)^(restricted|anonymous|private|unknown| unavailable)")
If you need to match the Display-Name ("Unavailable") then you must add the quotation marks to the regular expression:
pcre_match("$fn", "(?i)^(")?(restricted|anonymous|private|unknown| unavailable)(")?")
Note that I use $fn rather than $hdr("From"), being $fn the From Display-Name:
http://kamailio.org/dokuwiki/doku.php/pseudovariables:1.5.x#from_display_nam...
-- Iñaki Baz Castillo ibc@aliax.net
Kamailio (OpenSER) - Users mailing list Users@lists.kamailio.org http://lists.kamailio.org/cgi-bin/mailman/listinfo/users http://lists.openser-project.org/cgi-bin/mailman/listinfo/users
El Viernes, 18 de Septiembre de 2009, Brandon Armstead escribió:
Hello, I do not know why it did not dawn upon me to simply use the =~ operator. However it does appear to error out / not compile:
"(?i)(restricted|anonymous|private|unknown|unavailable)", i.e.
produces a runtime error:
if($hdr(From) =~ "(?i)(restricted|anonymous|private|unknown|unavailable)"){
}
Because =~ operator doesn't implement like (?i) sysntax. Use just:
"(restricted|anonymous|private|unknown|unavailable)"
Note that =~ uses case insensitive.
Inaki,
Ahah! thank you for this bit of information. Sent from my Verizon Wireless BlackBerry
-----Original Message----- From: Iñaki Baz Castillo ibc@aliax.net
Date: Fri, 18 Sep 2009 02:42:29 To: users@lists.kamailio.org Subject: Re: [Kamailio-Users] PCRE / Regex Module
El Viernes, 18 de Septiembre de 2009, Brandon Armstead escribió:
Hello, I do not know why it did not dawn upon me to simply use the =~ operator. However it does appear to error out / not compile:
"(?i)(restricted|anonymous|private|unknown|unavailable)", i.e.
produces a runtime error:
if($hdr(From) =~ "(?i)(restricted|anonymous|private|unknown|unavailable)"){
}
Because =~ operator doesn't implement like (?i) sysntax. Use just:
"(restricted|anonymous|private|unknown|unavailable)"
Note that =~ uses case insensitive.