fork(6) 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 fileText = "_test_";
  11. String pattern = "test";
  12. Pattern r = Pattern.compile(pattern);
  13. Matcher m = r.matcher(fileText);
  14. while (m.find()) {
  15. m.appendReplacement(sb, repeat("*", m.group(0).length()));
  16. }
  17. m.appendTail(sb); // append the rest of the contents
  18. System.out.println(sb);
  19. }
  20. public static String repeat(String s, int n) {
  21. if(s == null) {
  22. return null;
  23. }
  24. final StringBuilder sb = new StringBuilder(s.length() * n);
  25. for(int i = 0; i < n; i++) {
  26. sb.append(s);
  27. }
  28. return sb.toString();
  29. }
  30. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
_****_