fork(2) 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 s = "dfdfm;lg 2500$ jshfsnefsfz5405€mnvkjdf64rfmkd554668¢ odsfrknegj 885486¥ dsflkef 588525dollar";
  13. System.out.println(getPrice(s));
  14. }
  15.  
  16. private static List<String> getPrice(String caption) {
  17. String pricePattern = "(?i)(\\d[\\d,]*)\\s*(?:[$€¥¢]|dollar|Euro)";
  18. List<String> lstPrice = new ArrayList<>();
  19. Pattern rPrice = Pattern.compile(pricePattern);
  20. Matcher mPrice = rPrice.matcher(caption);
  21. while (mPrice.find()) {
  22. lstPrice.add(mPrice.group(1));
  23. }
  24. return lstPrice;
  25. }
  26. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
[2500, 5405, 554668, 885486, 588525]