fork download
  1. import java.util.regex.*;
  2.  
  3. class Ideone
  4. {
  5. public static void main (String[] args) {
  6. System.out.println(extractInt(""));
  7. System.out.println(extractInt("heyhow$98765$you"));
  8. System.out.println(extractInt("heyhow$$areyou"));
  9. System.out.println(extractInt("heyhow$xyz$areyou"));
  10. System.out.println(extractInt("heyhow$42x$areyou"));
  11. }
  12. private static int extractInt(String input) {
  13. Matcher m = Pattern.compile("\\$([0-9]+)\\$").matcher(input);
  14. if (! m.find())
  15. return 0;
  16. return Integer.parseInt(m.group(1));
  17. }
  18. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
0
98765
0
0
0