[Kamailio-Users] PCRE / Regex Module

Brandon Armstead brandon at cryy.com
Fri Sep 18 02:39:48 CEST 2009


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 at 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 at 192.168.47.68 <sip%3ARestricted at 192.168.47.68><
> sip%3ARestricted at 192.168.47.68 <sip%253ARestricted at 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_name
>
>
>
> --
> Iñaki Baz Castillo <ibc at aliax.net>
>
> _______________________________________________
> Kamailio (OpenSER) - Users mailing list
> Users at lists.kamailio.org
> http://lists.kamailio.org/cgi-bin/mailman/listinfo/users
> http://lists.openser-project.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20090917/3a3b407d/attachment.htm>


More information about the sr-users mailing list