fork(2) download
  1. import java.util.regex.*;
  2. import java.io.*;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
  9. String input = r.readLine();
  10.  
  11. Pattern p = Pattern.compile("abc");
  12. Matcher m = p.matcher(input);
  13.  
  14. m.find(); // what to do when there is no match?
  15. m.find(); // what to do when there is only one match?
  16.  
  17. System.out.println("Second match is between " + m.start() + " and " + m.end());
  18. }
  19. }
Success #stdin #stdout 0.07s 380160KB
stdin
abcXYabchZRabc
stdout
Second match is between 5 and 8