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

public static String filterNum(String text) {
    if (TextUtils.isEmpty(text))
        return "";

    return text.replaceAll("[^0-9]", "");
}

From source file:cloudfoundry.norouter.f5.Json.java

public static String unescape(String jsonish) {
    return jsonish.replaceAll("`", "\"");
}

From source file:Main.java

public static String formatString(String string) {
    if (string == null)
        return "";
    String newString = string.replaceAll(" ", "").replaceAll("-", "").replaceAll(",", "");
    return newString;
}

From source file:Main.java

/**
 * Remove all qualifiers in an XML code.
 *
 * @param xml the XML document/*from  w w w .  j a  v  a 2  s.  c o  m*/
 * @return the same document with unqualified element names
 */
public static String removeQualifiers(String xml) {
    // remove from elements
    xml = xml.replaceAll("<[^/:> ]+:", "<").replaceAll("</[^:> ]+:", "</");
    // remove namespace declarations
    xml = xml.replaceAll("xmlns:\\w+ *= *\"[^\"]*\"", "");
    // remove from attributes
    xml = xml.replaceAll("\" *\\w+ *: *(\\w+ *= *\")", "\" $1");
    xml = xml.replaceAll("(<\\w+ +)\\w+ *: *(\\w+ *= *\")", "$1$2");
    return xml;
}

From source file:Main.java

public static String noHTML(String text) {
    if (text == null)
        return "";
    else/*from  www.  ja  v a2  s .  c o m*/
        return text.replaceAll("\\<[\\w]+.*?>", "");
}

From source file:Main.java

private static String removeNamespaces(String xml) {
    // remove NS declarations
    xml = xml.replaceAll("xmlns:.*=\".*\"", "").replaceAll("xmlns=\".*\"", "").replaceAll("\\p{Space}+>", ">");
    // remove NS at element start
    xml = xml.replaceAll("<[^/\":]+:", "<");
    // remove NS at element end
    xml = xml.replaceAll("</[^\":]+:", "</");
    return xml;/*from  w  ww . java  2 s .  co m*/
}

From source file:org.runway.utils.TextUtils.java

public static String convertNewLineToBreak(String text) {

    String textChg = text.replaceAll("\n", "<br/>");

    return textChg;
}

From source file:de.jetwick.util.Translate.java

/**
 * Translates text from a given Language to another given Language using Google Translate.
 * /*from   w w  w. java 2s .  c  o m*/
 * @param text The String to translate.
 * @param from The language code to translate from.
 * @param to The language code to translate to.
 * @return The translated String.
 * @throws Exception on error.
 */
public static String execute(final String text, final Language from, final Language to) throws Exception {
    String url = URL.replaceAll("#FROM#", from.toString()).replaceAll("#TO#", to.toString())
            + URLEncoder.encode(text, "UTF8");
    JSONArray arr = new JSONArray(download(url));
    return arr.getJSONArray(0).getJSONArray(0).getString(0);
}

From source file:Main.java

public static String filterCharacter(String text) {
    if (TextUtils.isEmpty(text))
        return "";

    return text.replaceAll("[^0-9a-zA-Z\u4e00-\u9fa5]", "");

}

From source file:Main.java

private static float getFloatFromString(String s) {
    if (s != null && !s.trim().equals("")) {
        s = s.replaceAll(",", "");

        try {/*from  w  ww .  j  a  v  a  2s. c  o m*/
            if (s.endsWith("%")) {
                return Float.valueOf(s.substring(0, s.length() - 1));
            } else {
                return Float.valueOf(s);
            }
        } catch (NumberFormatException e) {
        }
    }

    return 0;
}