Contains support now regex as second argument
This commit is contained in:
parent
14e49d0099
commit
a410639627
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user