fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String str = "123 -111.9 ww1 111 q2q2 1";
  11. Pattern ptrn = Pattern.compile("[-+]?\\b\\d+(?:\\.\\d+)?\\b");
  12. Matcher matcher = ptrn.matcher(str);
  13. List<String> res = new ArrayList<>();
  14. while (matcher.find()) {
  15. res.add(matcher.group());
  16. }
  17. System.out.println(res);
  18. }
  19. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
[123, -111.9, 111, 1]