import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\(\\[(Modulus\\(\\d+\\)(?:\\s*,\\s*Modulus\\(\\d+\\))*)\\]\\):(\\(\\d+(?:,\\d+)*\\)x\\^\\d+(?:\\s*\\+\\s*\\(\\d+(?:,\\d+)*\\)x\\^\\d+)*)";
final String string = "RNS Polynomial ([Modulus(68719403009), Modulus(68719230977), Modulus(137438822401)]):(67699591241,42814670386,92925202514)x^0 + (42539574637,55054036653,135659663247)x^1 + (52858091297,11618896202,6855552742)x^2 + (45970532823,20845087073,91272562929)x^3 + (11148839321,55275439733,5401722690)x^4 + (31959765643,40620395732,93052536121)x^5 + (57030732406,66026147059,6304524013)x^6 + (27778918692,11276356856,61606736382)x^7\n";
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