Java Utililty Methods String Sanitize

List of utility methods to do String Sanitize

Description

The list of methods to do String Sanitize are organized into topic(s).

Method

Stringsanitize(String string)
sanitize
string = string.replace(" ", "");
string = string.replace(")(", ")*(");
StringBuilder result = new StringBuilder("");
int depth = 0;
for (int i = 0; i < string.length(); i++) {
    if (string.charAt(i) == '-' && depth == 0) {
        result.append("+(-1)*");
    } else {
...
Stringsanitize(String string, boolean allowWhitespace)
sanitize
if (allowWhitespace) {
    return string.replaceAll("[^A-Za-z0-9_ ]", "");
return string.replaceAll("[^A-Za-z0-9_]", "");
Stringsanitize(String string, String spaceReplace)
Sanitizes the provided message, removing any non-alphanumeric characters and swapping spaces with the specified string.
return string.replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", spaceReplace);
Stringsanitize(String text)
sanitize
if (text != null)
    return text.replaceAll("[,|;|\\.|-]", "");
return "";
Stringsanitize(String text)
sanitize
String result = text;
result = result.replaceAll(CHAR_8220, CHAR_QUOTE);
result = result.replaceAll(CHAR_8221, CHAR_QUOTE);
result = result.replaceAll(CHAR_8222, CHAR_QUOTE);
return result;
Stringsanitize(String value)
Remove non-alphabetic characters from a string
return value.toLowerCase().replaceAll("[^a-zA-Z]", "");
StringsanitizeAppAlias(String appAlias)
Make sure the app alias only has alphanumeric and common punctuation characters.
if (appAlias == null) {
    return null;
} else {
    return appAlias.replaceAll("[^\\w\\-'\"\\s]", "");
StringsanitizeAttribute(String value)
Nukes special attribute characters.
for (int ii = 0; ii < ATTR_ESCAPES.length; ++ii) {
    value = value.replace(ATTR_ESCAPES[ii][0], "");
return value;
StringsanitizeBranchName(String currentBranch)
sanitize Branch Name
return currentBranch.replaceAll("[\\s\\-#/\\\\]+", "_");
StringsanitizeBrowserName(String browserName)
sanitize Browser Name
browserName = browserName.toLowerCase();
browserName = browserName.replace("mobile", "").trim();
return browserName;