fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String fileText = "http://e...content-available-to-author-only...e.com//foo/bar 1: 2/";
  10. String pattern = "(\\bhttps?://\\S*)|[:/]";
  11.  
  12. Pattern r = Pattern.compile(pattern);
  13. Matcher m = r.matcher(fileText);
  14.  
  15. while (m.find()) {
  16. if (m.group(1) != null)
  17. m.appendReplacement(sb, m.group(1));
  18. else
  19. m.appendReplacement(sb, " ");
  20. }
  21. m.appendTail(sb); // append the rest of the contents
  22. System.out.println(sb);
  23. }
  24. }
Success #stdin #stdout 0.13s 320576KB
stdin
Standard input is empty
stdout
http://e...content-available-to-author-only...e.com//foo/bar  1  2