diff --git a/src/main/java/com/launchdarkly/client/Operator.java b/src/main/java/com/launchdarkly/client/Operator.java index b63c2c7e2..ac6b41cb3 100644 --- a/src/main/java/com/launchdarkly/client/Operator.java +++ b/src/main/java/com/launchdarkly/client/Operator.java @@ -42,7 +42,8 @@ public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) { }, matches { public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) { - return uValue.isString() && cValue.isString() && Pattern.matches(cValue.getAsString(), uValue.getAsString()); + return uValue.isString() && cValue.isString() && + Pattern.compile(cValue.getAsString()).matcher(uValue.getAsString()).find(); } }, contains { diff --git a/src/test/java/com/launchdarkly/client/OperatorTest.java b/src/test/java/com/launchdarkly/client/OperatorTest.java index 3557ea23b..7229225de 100644 --- a/src/test/java/com/launchdarkly/client/OperatorTest.java +++ b/src/test/java/com/launchdarkly/client/OperatorTest.java @@ -24,4 +24,13 @@ public void testNumberComparison() { assertTrue(Operator.greaterThan.apply(b, a)); assertTrue(Operator.greaterThanOrEqual.apply(b, a)); } + + @Test + public void testRegexComparison(){ + JsonPrimitive uValue = new JsonPrimitive("hello world"); + assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*rld"))); + assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*orl"))); + assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("l+"))); + assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("(world|planet)"))); + } }