Paste Search Dynamic
Recent pastes
String regex
  1. /* package whatever; // don't place package name! */
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5. import java.util.regex.Pattern;
  6. import java.util.regex.Matcher;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Main
  10. {
  11.         public static void main (string[] args) throws java.lang.exception
  12.         {
  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^7n";
  16.  
  17.         Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  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.                 string[] vars=matcher.group(2).split("x^");
  27.  
  28.                 for (string elm2 : vars[0].substring(1,vars[0].length()-1).split(","))
  29.                     system.out.println(elm2);
  30.             }
  31.         }
  32.  
  33.         }
  34. }
Parsed in 0.019 seconds