From a410639627d5b2b29f1fb141812312c7190c5470 Mon Sep 17 00:00:00 2001 From: Maxime Gobert Date: Wed, 28 Mar 2018 17:25:11 +0200 Subject: [PATCH] Contains support now regex as second argument --- .../google/refine/expr/functions/strings/Contains.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main/src/com/google/refine/expr/functions/strings/Contains.java b/main/src/com/google/refine/expr/functions/strings/Contains.java index dcfe23c57..99737b8de 100644 --- a/main/src/com/google/refine/expr/functions/strings/Contains.java +++ b/main/src/com/google/refine/expr/functions/strings/Contains.java @@ -34,6 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions.strings; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.json.JSONException; import org.json.JSONWriter; @@ -49,6 +51,14 @@ public class Contains implements Function { Object s2 = args[1]; if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof String) { return ((String) s1).indexOf((String) s2) > -1; + } else if (s1 != null && s2 != null && s1 instanceof String && s2 instanceof Pattern){ + String s = (String) s1; + Pattern pattern = (Pattern) s2; + Matcher matcher = pattern.matcher(s); + if (matcher.find()) { + return true; + }else + return false; } } return null;