fork(1) 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.*;
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String text = "The price is 1 000$ and 2 000 . 00 EUR another pice 34 000 , 00 EUR. You have to pay 1400 EUR, and you have to pay extra 2000$";
  13. String regex = "(\\bpay(?:\\s+extra)?\\s*)?([0-9][\\d\\s,.]*)(?:\\$|EUR)";
  14. Pattern pattern = Pattern.compile(regex);
  15. Matcher m = pattern.matcher(text);
  16. List<String> res = new ArrayList<>();
  17. while (m.find()) {
  18. if (m.group(1) == null) {
  19. res.add(m.group(2).replaceAll("[,.]\\s*\\d+|\\D", ""));
  20. }
  21. }
  22. System.out.println(res);
  23. }
  24. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
[1000, 2000, 34000]