fork download
  1. import java.util.List;
  2. import java.util.regex.MatchResult;
  3. import java.util.regex.Pattern;
  4. import java.util.stream.*;
  5.  
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. List<String> matches =
  10. Pattern.compile("\\d+")
  11. .matcher("123-8-90")
  12. .results()
  13. .flatMap(mr -> IntStream.rangeClosed(1, mr.groupCount())
  14. .mapToObj(mr::group))
  15. .collect(Collectors.toList());
  16.  
  17. System.out.println(matches);// [123, 8, 90]
  18. }
  19. }
Success #stdin #stdout 0.12s 56372KB
stdin
Standard input is empty
stdout
[]