code: private String stripPassword(String str)
     {
        if (str.indexOf("<password>") == -1)
           return str;
  
        Pattern pattern = Pattern.compile("<password>[^<]*</password>");
        String[] strs = pattern.split(str);
  
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strs.length; i++)
        {
           String s = strs[i];
           sb.append(s);
           if (i < strs.length - 1)
              sb.append("<password>****</password>");
        }
  
        return sb.toString();
     }
docs: Strip password
  @param str The string
  @return The result