fork 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 s1 = "abcXY123XYiXYjk";
  9. String s2 = java.util.regex.Pattern.quote("XY");
  10. String s3 = "";
  11. String r = "(?<=(.)|^)"+s2+"(?=(.)|$)";
  12. Pattern p = Pattern.compile(r);
  13. Matcher m = p.matcher(s1);
  14. while(m.find()) s3 += m.group(1)+m.group(2);
  15. System.out.println(s3);
  16. }
  17. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
c13iij