import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?i)UPDATE[ \\t\\n]{1,}(fact)(.*)\\n(from)?([ \\t\\n]{1,})?(.*)?\\n*set[ \\n\\t]{1,}(coloana)[ \\t\\n]*=[ \\t\\n]*(ifnull\\(\\s*)*([\\w\\d]*)([\\ ,'\\w\\n\\t)(\\n=.]*);";
final String string = "update fact,x2,asdasjsdjbmfeweoewo\n"
+ "from asdas,asaskdvd\n"
+ "set coloana = ifnull( ifnull( col2,'Test'), 'Test2')\n"
+ "where c = c.s.\n"
+ "and asdsa = asda.asda;\n\n"
+ "UPdate fact,x2\n"
+ "set coloana = ifnull(col2,'Test')\n"
+ "where c = c.s.;\n\n"
+ "update\n"
+ " fact,x2\n"
+ "from\n"
+ " asdas\n"
+ "set coloana = ifnull(col2,'Test')\n"
+ "where c = c.s.\n"
+ "and asdsa = asda.asda;\n\n"
+ "update fact,x2\n"
+ "from asdas\n"
+ "set coloana = (select x from y where x.fg = x2.asfds)\n"
+ "where c = c.s.\n"
+ "and asdsa = asda.asda;";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html