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