[SR-Users] Caseless regex

Daniel-Constantin Mierla miconda at gmail.com
Tue Oct 13 15:48:26 CEST 2020


Hello,

libpcre3 is known to be very fast, not sure you will notice any
performance impact because of runtime regular expression parsing,
everything being done in memory and for sure not with simple expressions
like "(?i)^test$". This happens because the parameters can have
variables, which are first evaluated, then used for matching.

Anyhow, a variant of the function with static parameter for regex can be
added easily.

On the other hand, you seem to compare with a full value, so you can
just use string comparison functions:

  *
https://www.kamailio.org/docs/modules/stable/modules/textops.html#textops.f.cmp_str

Cheers,
Daniel

On 13.10.20 15:22, Marat Gareev wrote:
> Henning, Daniel,
> thanks for your replies.
>
> 1. I don't want to use a Regex module because it might have a
> performance impact.
>
>     Matches the given string parameter against the regular expression
>     pcre_regex, which is compiled in runtime into a PCRE object.
>
>  
> 2.  I was surprised to find that the operator "=~" is case insensitive:
> if (regcomp(re, (char*) exp->r.param,
> REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
> LM_CRIT("bad re \"%s\"\n", (char*) exp->r.param);
> pkg_free(re);
> return E_BAD_RE;
> }
> so that enough for me:
> $tU =~ "^test$"
> Btw, what if I need case sensitive validation? Should I use the Regex
> module?
>
> Regards,
> Marat
>
> вт, 13 окт. 2020 г. в 14:17, Daniel-Constantin Mierla
> <miconda at gmail.com <mailto:miconda at gmail.com>>:
>
>     Hello,
>
>     adding some more details to mention that regex operations done by
>     the core (the =~ operator) use the libc posix regex functions,
>     which do not support extended syntax. Also, these operations done
>     by core use the case insensitive flag.
>
>     As mentioned by Henning, regex should be an alternative, or maybe
>     dialplan if one wants db-storage+caching of those regex rules.
>
>     Moreover, if the above are not enough, a kemi embedded interpreter
>     (e.g., app_lua, app_python) can be used with inline execution in
>     kamailio.cfg routing blocks -- those external scripting languages
>     should have many options for regex matching.
>
>     Cheers,
>     Daniel
>
>     On 13.10.20 13:04, Henning Westerholt wrote:
>>
>>     Hello,
>>
>>      
>>
>>     just an idea, have you already tried this module:
>>     https://www.kamailio.org/docs/modules/stable/modules/regex.html
>>     <https://www.kamailio.org/docs/modules/stable/modules/regex.html>
>>
>>      
>>
>>     Cheers,
>>
>>      
>>
>>     Henning
>>
>>      
>>
>>     -- 
>>
>>     Henning Westerholt – https://skalatan.de/blog/
>>     <https://skalatan.de/blog/>
>>
>>     Kamailio services – https://gilawa.com <https://gilawa.com/>
>>
>>      
>>
>>     *From:* sr-users <sr-users-bounces at lists.kamailio.org>
>>     <mailto:sr-users-bounces at lists.kamailio.org> *On Behalf Of *Marat
>>     Gareev
>>     *Sent:* Tuesday, October 13, 2020 10:55 AM
>>     *To:* Kamailio (SER) - Users Mailing List
>>     <sr-users at lists.kamailio.org> <mailto:sr-users at lists.kamailio.org>
>>     *Subject:* [SR-Users] Caseless regex
>>
>>      
>>
>>     Hello,
>>
>>      
>>
>>     Is it possible write more readable regular expression
>>
>>     if($tU =~ "(?i)^test$") {
>>
>>         ...
>>
>>     }
>>
>>     instead of"^[tT][eE][sS][tT]$"?
>>
>>      
>>
>>     On the first option, I get the error:
>>
>>     0(47250) ERROR: <core> [core/rvalue.c:3038]: fix_match_rve(): Bad
>>     regular expression
>>
>>      
>>
>>     Regards,
>>
>>     Marat
>>
>>
>>     _______________________________________________
>>     Kamailio (SER) - Users Mailing List
>>     sr-users at lists.kamailio.org <mailto:sr-users at lists.kamailio.org>
>>     https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users <https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users>
>
>     -- 
>     Daniel-Constantin Mierla -- www.asipto.com <http://www.asipto.com>
>     www.twitter.com/miconda <http://www.twitter.com/miconda> -- www.linkedin.com/in/miconda <http://www.linkedin.com/in/miconda>
>     Funding: https://www.paypal.me/dcmierla <https://www.paypal.me/dcmierla>
>
>     _______________________________________________
>     Kamailio (SER) - Users Mailing List
>     sr-users at lists.kamailio.org <mailto:sr-users at lists.kamailio.org>
>     https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>     <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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20201013/30a0a68a/attachment.htm>


More information about the sr-users mailing list