On Thu, Oct 24, 2013 at 11:18 PM, Pavel Levshin <[email protected]>wrote:

> Hello.
>
> I hope it will be useful. Now, when local variables are real JSON
> containers, why don't extract all submatches at once? I've given it a try
> and it works. The patch is based on a current master-var-refactor, I am
> sorry for this mess. I will redo it if needed when the refactoring will be
> done.
>
> I've extended re_extract to achieve this behaviour. Creation of a new
> function (re_extract_all) just for this would lead to code duplication. The
> modified function returns a container with all submatches on request.
> Submatches in the container are identified by index, where "0" is whole
> match. New behaviour is achieved by setting 'submatch' parameter to any
> negative number. For non-negative numbers, it works as it used to. Example:
>
> # re_extract(expr, re, match, submatch, no-found)
>
>     set $.str = "Testing 31 32 33 and so on";
>     set $.var = re_extract($.str, "^([[:alnum:]]+) ([0-9]+) ([0-9]+)", 0,
> -1, "nothing");
>     set $!matches = $.var;            # container here
>     set $!match2 = $.var!2;          # 2nd submatch
>
> And here is the output of all these variables (with some magic template):
>
> _local_ { "str": "Testing 31 32 33 and so on", "var": { "0": "Testing 31
> 32", "1": "Testing", "2": "31", "3": "32" } }
> _msg_ { "matches": { "0": "Testing 31 32", "1": "Testing", "2": "31", "3":
> "32" }, "match2": "31" }
>
>
I think this is a very useful addition, but I am a bit hesitant to
introduce some kind of array as a side-effect. Please let me think a bit
about this. My gut feeling is that we should add it as a new function
re_extract_experimental(), which is not guaranteed to stay in the future.
We could still use current code.

Once we have native array support (a thing that's desirable), I don't want
to necessarily carry over that legacy (there's already so much legacy, some
modules have more code lines to support legacy than what they need for
current work...).

As you say you still work on the patch, I'll stand a bit by until you say
it's stable enough to be merged experimentally ;)

>
> By the way, this patch also fixes a bug with buffer overflow in re_extract.
>

Will look into this. It would save me a copule of minutes if you could
point me at it.

Rainer



>
>
> --
> Pavel Levshin
>
>
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com/professional-services/
> What's up with rsyslog? Follow https://twitter.com/rgerhards
> NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad
> of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you
> DON'T LIKE THAT.
>
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to