0

I'm trying to do something like this in Open/Google Refine:

forEach(["foo", "bar"], regex, value.match(/.*(regex).*/))

That is loop an array of keywords to check if the cell contains any of them. How can I use these keywords to build regular expressions?

Any ideas?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jens
  • 121
  • 1
  • 9

1 Answers1

0
import java.util.regex.*;

public class PatternExample {
    public static void main(String[] args) {
        String arr_regex[] = {"foo", "bar"};
        String arr_str[] = {"abcfoodef", "cbard"};
        int i = 0;
        for(String str : arr_str) {
            Pattern pattern = Pattern.compile("(?i).*"+arr_regex[i]+".*");
            Matcher matcher = pattern.matcher(str);
            System.out.println("Input String matches regex - "+matcher.matches());
            i++;
        }
    }
}

I think this is pretty much you wanted. Example is in java but will show you how to do it

Rizstien
  • 802
  • 1
  • 8
  • 23