fork(2) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4.  
  5. class Main {
  6. public static void main (String[] args) throws java.lang.Exception {
  7.  
  8. String input= "(2 h 9 min from now) | +18.7 feet";
  9. System.out.println("Input: "+ input);
  10. Pattern p = Pattern.compile("\\(([^)]+)\\) \\| \\+(\\d+\\.\\d feet)");
  11. Matcher m = p.matcher(input);
  12. String a = null, b = null;
  13. if (m.find()) {
  14. a = m.group(1);
  15. b = m.group(2);
  16. }
  17. System.out.println("a: "+ a);
  18. System.out.println("b: "+ b);
  19. }
  20. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Input: (2 h 9 min from now) | +18.7 feet
a: 2 h 9 min from now
b: 18.7 feet