Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Support multiple matches in regex() function #197

Closed
wants to merge 1 commit into from
Closed

Conversation

joschi
Copy link
Contributor

@joschi joschi commented Jul 5, 2017

The regex() function only returned a single match (similar to the Regex Extractor),
while some users require it to return all matches.

Fixes #173
Closes #174

The regex() function only returned a single match (similar to the Regex Extractor),
while some users require it to return all matches.

Fixes #173
Closes #174
@joschi joschi added this to the 2.3.0 milestone Jul 5, 2017
@joschi joschi requested a review from kroepke July 5, 2017 10:14
@bernd bernd modified the milestones: 3.0.0, 2.3.0 Jul 5, 2017
@joschi joschi added bug and removed enhancement labels Jul 5, 2017
@bernd bernd modified the milestones: 2.4.0, 3.0.0 Jul 18, 2017
@hc4
Copy link

hc4 commented Aug 11, 2017

Looks like this PR broke multi-group matching.
E.g. let result = regex("(a)(b)(c)", "abcabc");
There will be 2 matches with 3 groups in each.
How to access them?

Moreover - this PR broke current regex behaviour, because currently indexer of regex result returns groups of first match, but after this PR it will return matches by index

@joschi
Copy link
Contributor Author

joschi commented Aug 11, 2017

@hc4 It's not possible to properly model multiple group matches because the function language lacks iteration/looping primitives.

I'll close this PR…

@joschi joschi closed this Aug 11, 2017
@joschi joschi deleted the issue-173 branch August 11, 2017 10:02
@hc4
Copy link

hc4 commented Aug 11, 2017

@joschi, do you mean multiple matches?
Because I'am using multi-group feature in my rules right now and everything works fine.

  let m = regex("^(?:\\d+),(\\d+),\\d+,(.*)$", to_string($message.message));
  set_field("temperature", to_double(m["0"]));
  let tz = to_string(lookup_value("temper-tz", $message.source));
  let date = parse_date(value: to_string(m["1"]), pattern: "yyyy-MM-dd HH:mm:ss", locale: "", timezone: tz);
  set_field("timestamp", date);

m["0"] gives me first group and m["1"] gives me the second one.

@joschi joschi mentioned this pull request Sep 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants