fork(2) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Main
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String a = "XY1XY";
  9. String b = "XY";
  10. String c = "";
  11. Matcher m = Pattern.compile("(.|)" + Pattern.quote(b) + "(?=(.?))").matcher(a);
  12. for (int i = 1; m.find(); c += m.group(1) + m.group(2), i++);
  13. System.out.println(c);
  14. }
  15. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
11