fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Pattern p = Pattern.compile("(\\d)");
  14. String myString = "12345";
  15. Matcher matcher = p.matcher(myString);
  16.  
  17. if(matcher.find()) { // expecting 1
  18. System.out.println(matcher.group(1));
  19. }
  20. if(matcher.find()) { // expecting 2
  21. System.out.println(matcher.group(1));
  22. }
  23. if(matcher.find()) { // expecting 3
  24. System.out.println(matcher.group(1));
  25. }
  26. matcher.reset();
  27.  
  28.  
  29. if(matcher.find()) { // expecting 1
  30. System.out.println(matcher.group(1));
  31. }
  32. }
  33. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
1
2
3
1