fork(38) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = "plan plans lander planitia";
  11. String pattern = "\\w*(lan)\\w+";
  12. Pattern r = Pattern.compile(pattern);
  13. Matcher m = r.matcher(text);
  14. while (m.find()) {
  15. m.appendReplacement(sb, m.group(0).replaceFirst(Pattern.quote(m.group(1)), "<--->"));
  16. }
  17. m.appendTail(sb); // append the rest of the contents
  18. System.out.println(sb.toString());
  19. }
  20. }
Success #stdin #stdout 0.09s 320512KB
stdin
Standard input is empty
stdout
plan p<--->s <--->der p<--->itia