SHARE
TWEET

Untitled

a guest Feb 19th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (int1,int2) (int3,int4)
  2.    
  3. String[] ints = "(2,3) (4,5)".split("\D+");
  4. System.out.println(Arrays.asList(ints));
  5. // prints [, 2, 3, 4, 5]
  6.    
  7. String[] ints = "(2,3) (4,5)".replaceAll("^\D*(.*)\D*$", "$1").split("\D+");
  8. System.out.println(Arrays.asList(ints));
  9. // prints [2, 3, 4, 5]
  10.    
  11. Pattern p = Pattern.compile("\((\d+),(\d+)\)\s+\((\d+),(\d+)\)");
  12. String input = "(123,456) (789,012)";
  13.  
  14. Matcher m = p.matcher(input);
  15.  
  16. if (m.matches()) {
  17.   int a = Integer.parseInt(m.group(1), 10);
  18.   int b = Integer.parseInt(m.group(2), 10);
  19.   int c = Integer.parseInt(m.group(3), 10);
  20.   int d = Integer.parseInt(m.group(4), 10);
  21. }
  22.    
  23. String str = "(1,2) (3,4)";
  24. Matcher m = Pattern.compile("\((\d+),(\d+)\) \((\d+),(\d+)\)").matcher(str);
  25. if (m.matches()) {
  26.    System.out.println(m.group(1)); // number 1
  27.    ...
  28. }
  29.    
  30. String s = "(1,2) (3,4)";
  31. Pattern p = Pattern.compile("\d+");
  32. Matcher m = p.matcher(s);
  33. while (m.find()) {
  34.     System.out.println(m.group());
  35. }
  36.    
  37. String[] values = s.substring(1).split("\D+");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top