Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filterx regexp_subst supports match groups #394

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

bshifter
Copy link
Member

Enhanced regexp_subst to support match group identifiers in patterns.

Since this feature could have a significant impact on performance, it is
controlled by a flag called 'groups', which is set to false by default.
To enable this feature, add the optional groups=true argument to your regexp_subst call.

example:

filterx{
  $MSG.on = regexp_subst("25-02-2022", /(\d{2})-(\d{2})-(\d{4})/, "\\3/\\2/\\1", groups=true);
  # returns "2022\/02\/25"
}

This feature could have been implemented using the pcre2_substitute() function provided by the PCRE2 library. However, this approach was not viable because pcre2_substitute() does not support zero-length matches, which are a critical aspect of syslog-ng's legacy regex matcher.

As a result, the implementation introduced unwanted/unnecessary code and increased complexity. Given this, I would recommend discontinuing support for zero-length matches in filterx regexps. This change would improve both performance and code maintainability. While zero-length matches may seem like a useful feature in regular expressions, their practical use cases are likely to be rare and non-critical.

@bshifter bshifter changed the title Filterx regx subst supports match grps Filterx regexp_subst supports match grps Nov 27, 2024
@bshifter bshifter changed the title Filterx regexp_subst supports match grps Filterx regexp_subst supports match groups Nov 27, 2024
…patterns

Since this feature could have a significant impact on performance, it is
controlled by a flag called 'groups', which is set to false by default.
To enable this feature, add the optional groups=true argument to your regexp_subst call.

Signed-off-by: shifter <shifter@axoflow.com>
Signed-off-by: shifter <shifter@axoflow.com>
Signed-off-by: shifter <shifter@axoflow.com>
+ additional unit test for enabled but unused 'group' feature

Signed-off-by: shifter <shifter@axoflow.com>
Copy link
Member

@alltilla alltilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

This could have a news entry, but it is enough to do in another PR.

@alltilla alltilla merged commit e22db34 into axoflow:main Dec 3, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants