[SR-Users] How to use regular expression for $var ?

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 17 08:50:04 CEST 2012


Hello,

On 7/16/12 4:32 PM, Gary Chen wrote:
>
> Kamailio 3.3.0
>
> I have a variable  $var(s:dst). It can store either a number or IP.
>
> How do I check to determine whether it is a number of IP?
>
> I tried the following and it did not work:
>
> If ($var(s:dst) =~ "^\d+\.\d+\.\d+\.\d+$"){
> It is a IP.
> }else{
> It is a Number
> }
for this particular case, you better use functions from ipops module:

http://kamailio.org/docs/modules/stable/modules/ipops.html#id2536192

Using regular expressions with variables is correct as you tried, not 
sure the \d is taken on consideration, you may try \\d or what I usually 
use is [0-9] instead of \d.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio Advanced Training, Seattle, USA, Sep 23-26, 2012 - http://asipto.com/u/katu
Kamailio Practical Workshop, Netherlands, Sep 10-12, 2012 - http://asipto.com/u/kpw

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20120717/778796e6/attachment-0001.htm>


More information about the sr-users mailing list