[SR-Users] Regular Expression Evaluation

Daniel-Constantin Mierla miconda at gmail.com
Thu Sep 10 09:18:57 CEST 2020


This one with matching 4 numbers separated by dots is better, one can
add restrictions that the last two numbers are in the range 0-255, if
one wants to be more strict, but the expression will get more complex.

However, it is recommended to use ^ and $ to enclose the expression and
do not match hostnames like my10.10.10.10domain.com.

The first example in this discussion $rd =~ "10\.10\..+" can match also
other ips not in wanted range, like 8.10.10.23

As for matching the . (dot), it  has to be escaped like \., however over
the time working with different libraries, scripting languages and
parameters evaluation (which may require \\.) I developed the habit of
using [ ] for matching the special characters, like here it would be $rd
=~ "^10[.]10[.].+".

Just to follow on Alex' remark.

Otherwise, the match with ipops function is the most accurate for this case.

To complete for those that are not aware of, one can avoid regex
matching if wanted to match on prefix: starts_with("$rd", "10.10.").
Then fnmatch() function can be also useful in some cases, it does
shell-like pattern matching for file names.

Cheers,
Daniel

On 09.09.20 22:18, Fred Posner wrote:
> I had an extra 10 in there ;)
>
> if ((is_method("INVITE")) && 
> ($rd =~ "10\.10\.[[:digit:]]+\.[[:digit:]]+")) {
>
> or
>
> if ((is_method("INVITE")) && 
> ($rd =~ "10\.10\.[0-9]+\.[0-9]+")) {
>
> --fred
>
> On Wed, 2020-09-09 at 16:15 -0400, Fred Posner wrote:
>> I would try:
>>
>> if(uri=~"10\.10\.10\.[[:digit:]]+\.[[:digit:]]+")
>>
>> or
>>
>> if(uri=~"10\.10\.10\.[0-9]+\.[0-9]+")
>>
>> --fred
>>
>> On Wed, 2020-09-09 at 15:53 -0400, Alex Balashov wrote:
>>> The answer to the question as posed would also be interesting,
>>> however. 
>>> It seems to me it should work.
>>>
>>> On 9/9/20 3:34 PM, Mack Hendricks wrote:
>>>> I already run into issues with this.  If I want to only execute
>>>> a
>>>> statement if it’s an INVITE with a request domain of 10.10.*.*
>>>> how
>>>> do I format?  Below is what I have.   I always have to play with
>>>> it a bit.   Looking to get a better understanding.  The regular
>>>> expression tester I’m using states that it’s valid.  What am I
>>>> doing wrong?
>>>>
>>>>   if ((is_method("INVITE")) && ($rd =~ "10\.10\..+")) {
>>>>
>>>>                  # Do something
>>>>                  xlog("fix got a 10.10 address");
>>>>
>>>>          }
>>>>
>>>> Thanks
>>>> _______________________________________________
>>>> Kamailio (SER) - Users Mailing List
>>>> sr-users at lists.kamailio.org
>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>
>>>
>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Funding: https://www.paypal.me/dcmierla




More information about the sr-users mailing list