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

Commit

Permalink
Use find in the regex function (#88)
Browse files Browse the repository at this point in the history
Do not force regular expressions passed to `regex()` to match the whole
string.

Fixes #35
  • Loading branch information
edmundoa authored and kroepke committed Aug 18, 2016
1 parent a2ec829 commit 3298411
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public RegexMatchResult evaluate(FunctionArgs args, EvaluationContext context) {
(List<String>) optionalGroupNames.optional(args, context).orElse(Collections.emptyList());

final Matcher matcher = regex.matcher(value);
final boolean matches = matcher.matches();
final boolean matches = matcher.find();

return new RegexMatchResult(matches, matcher.toMatchResult(), groupNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public void regexMatch() {
assertNotNull(message);
assertTrue(message.hasField("matched_regex"));
assertTrue(message.hasField("group_1"));
assertThat((String) message.getField("named_group")).isEqualTo("cd.e");
} catch (ParseException e) {
Assert.fail("Should parse");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
rule "regexMatch"
when
regex(".*(cde\\.)(:(\\d+))?.*", "abcde.fg").matches == true
regex("^.*(cde\\.)(:(\\d+))?.*$", "abcde.fg").matches == true &&
regex(".*(cde\\.)(:(\\d+))?.*", "abcde.fg").matches == true &&
regex("(cde\\.)(:(\\d+))?", "abcde.fg").matches == true &&
regex("^(cde\\.)(:(\\d+))?$", "abcde.fg").matches == false
then
let result = regex(".*(cd\\.e).*", "abcd.efg");
let result = regex("(cd\\.e)", "abcd.efg");
set_field("group_1", result["0"]);
let result = regex("(cd\\.e)", "abcd.efg", ["name"]);
set_field("named_group", result["name"]);
set_field("matched_regex", result.matches);
end

0 comments on commit 3298411

Please sign in to comment.