fork(10) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone {
  7. public static void main(String[] args) throws java.lang.Exception {
  8. // Check for rude words before sending to server
  9. String result = "heres bilbobaggins haha";
  10. String patternString = "(bilbo|baggins|in|the|shire)";
  11. Pattern pattern = Pattern.compile(patternString);
  12. Matcher findRudeWords = pattern.matcher(result.toLowerCase());
  13.  
  14. while (findRudeWords.find()) {
  15. // Replace the bad word with astericks
  16. result = result.replaceAll("(?i)" + findRudeWords.group(1), "*");
  17. }
  18. System.out.println("result=" + result);
  19. }
  20.  
  21. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
result=heres ** haha