fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Pattern;
  7. import java.util.regex.Matcher;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String regex = "\\(\\[(Modulus\\(\\d+\\)(?:\\s*,\\s*Modulus\\(\\d+\\))*)\\]\\):(\\(\\d+(?:,\\d+)*\\)x\\^\\d+(?:\\s*\\+\\s*\\(\\d+(?:,\\d+)*\\)x\\^\\d+)*)";
  15. 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";
  16.  
  17. Pattern pattern = Pattern.compile(regex);
  18. Matcher matcher = pattern.matcher(string);
  19.  
  20. while (matcher.find()) {
  21. if (matcher.group(1) != null) {
  22. for (String elm1 : matcher.group(1).split(",\\s*"))
  23. System.out.println(elm1);
  24. }
  25. if (matcher.group(2) != null) {
  26. for (String elm2 : matcher.group(2).split("\\s*\\+\\s*"))
  27. System.out.println(elm2);
  28. }
  29. }
  30. }
  31. }
Success #stdin #stdout 0.09s 48476KB
stdin
Standard input is empty
stdout
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