code: public static String sanitize (String source, String charRegex)
      {
          final StringBuilder buf = new StringBuilder(" ");
          final Matcher matcher = Pattern.compile(charRegex).matcher(buf);
          return sanitize(source, new CharacterValidator() {
              public boolean isValid (char c) {
                  buf.setCharAt(0, c);
                  return matcher.matches();
              }
          });
      }
docs: Sanitize the specified String such that each character must match against the regex
  specified.