Java tutorial
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) throws Exception { String input = "123 321 443 52134 432"; Pattern pattern = Pattern.compile("\\d+"); Matcher matcher = pattern.matcher(input); int i = 0; while (matcher.find()) { ++i; } System.out.printf("Matched %d times%n", i); } }