fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String REGEX = "data|you|Us";
  13. final String MASK = "****";
  14. final Pattern PATTERN = Pattern.compile(REGEX);
  15. String message = "Hai man how are you ? Give me data which you have fetched as it is very important data to Us";
  16. Matcher matcher = PATTERN.matcher(message);
  17. StringBuffer result = new StringBuffer();
  18. while (matcher.find()) {
  19. String replacement =
  20. matcher.group(0).replaceAll(".", MASK.substring(0, 1));
  21. matcher.appendReplacement(result, replacement);
  22. }
  23. matcher.appendTail(result);
  24. System.out.println(result.toString());
  25.  
  26. }
  27. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Hai man how are *** ? Give me **** which *** have fetched as it is very important **** to **