Example usage for java.lang String replaceAll

List of usage examples for java.lang String replaceAll

Introduction

In this page you can find the example usage for java.lang String replaceAll.

Prototype

public String replaceAll(String regex, String replacement) 

Source Link

Document

Replaces each substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:edu.harvard.i2b2.crc.util.StringUtil.java

public static String escapeSQLSERVER(String sql) {

    sql = sql.replaceAll("\\?", "??");
    sql = sql.replaceAll("_", "?_");
    sql = sql.replaceAll("%", "?%");
    sql = sql.replaceAll("\\[", "?[");
    //   sql += "%";

    return sql;/* ww  w  .java 2 s. c  o m*/
}

From source file:Main.java

public static boolean isMobilePhone(String tel) {
    if (tel.contains(" ")) {
        tel = tel.replaceAll(" ", "");
    }//from w ww . j  av  a  2  s  .  c  o m

    if (tel.contains("-")) {
        tel = tel.replaceAll("-", "");
    }
    Pattern p = Pattern.compile("(1)\\d{10}$");
    return p.matcher(tel).matches();
}

From source file:Main.java

public static String replaceAllXMLCharacters(String document) {
    String returnDocument = "";
    returnDocument = document.replaceAll("<", "&lt;");
    return returnDocument.replaceAll(">", "&gt;");
}

From source file:Main.java

public static String replaceAllXMLEscapeCharacters(String document) {
    String returnDocument = "";
    returnDocument = document.replaceAll("&lt;", "<");
    return returnDocument.replaceAll("&gt;", ">");
}

From source file:Main.java

/**
 * Generates valid component id from component name (see general comments in
 * class {@link ComponentIDUtil})/* www  .ja  v  a 2  s  .  co  m*/
 * 
 * @param compName
 * @return
 */
public static String generateIDFromName(String compName) {
    String alphaDigitsUnderscoreDashString = compName.replaceAll("[^a-zA-Z0-9\\-\\_]+", "_");
    if (alphaDigitsUnderscoreDashString.matches("^[0-9].*")) {
        alphaDigitsUnderscoreDashString = "_" + alphaDigitsUnderscoreDashString;
    }
    return alphaDigitsUnderscoreDashString;
}

From source file:fr.obeo.dsl.designer.gen.html.services.StringUtils.java

/**
 * Replace forbidden characters with "_" in a filename
 * @param name/*from   ww w .j  a v  a 2 s  . c o m*/
 * @return sanitized string
 */
public static String sanitizeFilename(String name) {
    return name.replaceAll("[:\\\\/*?|<>]", "_");
}

From source file:Main.java

public static String noHTMLButSmiley(String text) {
    if (text == null)
        return "";
    return text.replaceAll(REGEX_HTML, "");
}

From source file:Main.java

/**
 * TODO:  Eliminate the mungling on the client-side instead of
 * attempting very problematic correction here!
 *//* w  ww  .jav  a 2s .  c  om*/
static String revertMungledPreparedQuery(String inQuery) {
    // THIS PURPOSEFULLY USING Java 1.4!
    return inQuery.replaceAll("\\$\\d+", "?");
}

From source file:Main.java

/**
 * Replace pattern [SCILAB_FIGURE_ID] by the figure index
 * @param initialString string read in XML file
 * @param parentFigureId the figure ID/*  ww w. jav  a  2  s . c  o  m*/
 * @return callback string
 */
private static String replaceFigureID(String initialString, Integer parentFigureId) {
    return initialString.replaceAll("\\[SCILAB_FIGURE_ID\\]", Integer.toString(parentFigureId));
}

From source file:Main.java

@SuppressWarnings("nls")
static String clean(String msg) {
    return msg.//
            replaceAll("(?i)(?m)^Signed-off-by:.*$\n?", "").// //$NON-NLS-1$
            replaceAll("(?m)^#.*$\n?", "").// //$NON-NLS-1$
            replaceAll("(?m)\n\n\n+", "\\\n").// //$NON-NLS-1$
            replaceAll("\\n*$", "").// //$NON-NLS-1$
            replaceAll("(?s)\ndiff --git.*", "").// //$NON-NLS-1$
            trim();//from   w w  w  . j a  v a 2  s  .  com
}