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:Main.java

/**
 * This method transform XPath and delete prefix of namespaces
 * @param xpath/*from  w  w  w. j  a va2s  .c  o  m*/
 * @return
 */
public static String removePrefixNS(String xpath) {
    return xpath.replaceAll(new Regexp("[/][a-z]*[:]").exp, "/");
}

From source file:Main.java

public static String sanitizeUserInput(String usrInput) {
    String lower = usrInput.toLowerCase();
    if (lower.replaceAll("[^a-z]", "").isEmpty()) {
        return "";
    }//from  ww w . j a  v a 2s .co  m
    String alphabetic = lower.replaceAll("[^a-z ]", "");
    return alphabetic.replaceAll("[ ]", "+");
}

From source file:Main.java

public static void printTextValue(OutputStream out, String str) throws IOException {
    str = str.replaceAll("&", "&"); //$NON-NLS-1$ //$NON-NLS-2$
    str = str.replaceAll(">", ">"); //$NON-NLS-1$ //$NON-NLS-2$
    str = str.replaceAll("<", "&lt;"); //$NON-NLS-1$ //$NON-NLS-2$
    print(out, str);/*from w  w  w. j  a v  a 2s .c om*/
}

From source file:Main.java

private static String encodeXML(String text) {
    String escapedXML = text;
    escapedXML = escapedXML.replaceAll("&", "&amp;");

    escapedXML = escapedXML.replaceAll("<", "&lt;");
    escapedXML = escapedXML.replaceAll(">", "&gt;");
    escapedXML = escapedXML.replaceAll("\"", "&quot;");
    escapedXML = escapedXML.replaceAll("'", "&apos;");
    return escapedXML;
}

From source file:Main.java

/**
 * <p>First line unfolds all the labels
 * Second line unfolds all the lines (if needed.)</p>
 * /*  ww  w  .  j  ava  2s .co  m*/
 * <p>This unfolding technique is according to the MIME-DIR specifications
 * as described in section 5.8.1 "Line delimiting and folding."</p>
 * 
 * @param vcardString
 * @return {@link String}
 */
public static String unfoldVCard(String vcardString) {
    String unfold1 = vcardString.replaceAll("=\n\\p{Blank}+", "");
    String unfold2 = unfold1.replaceAll("\n\\p{Blank}+", "");
    return unfold2;
}

From source file:Main.java

/** return version of the string that is ready for xml output (i.e. convert '<' to '&lt', etc)
 *//*w  ww.ja v  a2 s.co m*/
public static String xmlSafe(String s) {
    String safeString = s;

    safeString = safeString.replaceAll("&", "&amp;");
    safeString = safeString.replaceAll("<", "&lt;");
    safeString = safeString.replaceAll(">", "&gt;");
    safeString = safeString.replaceAll("'", "&apos;");
    safeString = safeString.replaceAll("\"", "&quot;");
    return safeString;
}

From source file:com.switchfly.compress.TestingUtil.java

public static String normalizeWhiteSpace(String s) {
    return s.replaceAll("\\s+", "").trim();
}

From source file:Main.java

@NonNull
private static String getFormattedSource(@NonNull String source) {
    return source.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
}

From source file:Main.java

/**
 *  This is pretty slow... But it's okay, XML export does not need to be very speedy.
 *  @param src//from ww  w.  ja  va 2 s.  c  om
 *  @return
 */
public static String escapeXML(String src) {
    src = src.replaceAll("&", "&amp;");
    src = src.replaceAll("<", "&lt;");
    src = src.replaceAll(">", "&gt;");
    src = src.replaceAll("\"", "&quot;");
    src = src.replaceAll("'", "&apos;");

    return src;
}

From source file:Main.java

/**
 * Replaces new lines with spaces; '&&' with AND; '||' with OR // these two can be removed once HIVE-5326 gets
 * resolved.//from  w  ww  .  j a  va 2 s.com
 *
 * @param query the query
 * @return the replaced query
 */
static String getReplacedQuery(final String query) {
    return query.replaceAll("[\\n\\r]", " ").replaceAll("&&", " AND ").replaceAll("\\|\\|", " OR ").trim();
}