import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:(?<!\")(?:\"\")*\"[^\"]*(?:\"\"[^\"]*)*\"|\\w+!)(*SKIP)(*F)|\\b[A-Z]+\\K\\d+\\b";
final String string = "SI(F5=\"\";\"\";\"Z_PACK_TYPE\")\n"
+ "MARKET!A5\n"
+ "MARKET!MQ5\n"
+ "MARKET!AB5\n"
+ "MARKET!TX5\n"
+ "MARKET!SX5\n"
+ "MATMAS05!CZ5=\"3200\";MARKET!DA5\n"
+ "SI(MATMAS05!CZ5=\"3200\";MATMAS05!CZ5=\"3200\";MARKET!DA5;\"\")\n"
+ "SI(L5=\"\";\"\";\"STRING\")\n"
+ "SI(MATMAS05!CZ5=\"3300\";MARKET!DA5;\"\"\n"
+ "SI(ESTVIDE(MARKET!EG5);\"\";SI(MATMAS05!CZ5=\"3200\";MARKET!EG5;\"\")";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (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