fork(18) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main
  5. {
  6. public static void main(String a[]){
  7. String stream = "ab34ef";
  8. Pattern pattern = Pattern.compile("\\d*");
  9.  
  10. //HERE * IS GREEDY QUANTIFIER THAT LOOKS FOR ZERO TO MANY COMBINATION THAT
  11. //START WITH NUMBER
  12. Matcher matcher = pattern.matcher(stream);
  13.  
  14. while(matcher.find()){
  15. System.out.println(matcher.start()+ ": " + matcher.group());
  16. }
  17. }
  18. }
  19.  
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
0: 
1: 
2: 34
4: 
5: 
6: