Example usage for org.apache.commons.lang3 RegExUtils removeAll

List of usage examples for org.apache.commons.lang3 RegExUtils removeAll

Introduction

In this page you can find the example usage for org.apache.commons.lang3 RegExUtils removeAll.

Prototype

public static String removeAll(final String text, final String regex) 

Source Link

Document

Removes each substring of the text String that matches the given regular expression.

This method is a null safe equivalent to:
  • text.replaceAll(regex, StringUtils.EMPTY)
  • Pattern.compile(regex).matcher(text).replaceAll(StringUtils.EMPTY)

A null reference passed to this method is a no-op.

Unlike in the #removePattern(String,String) method, the Pattern#DOTALL option is NOT automatically added.

Usage

From source file:de.jfachwert.net.Telefonnummer.java

/**
 * Liefert die Vorwahl oder auch Ortskennzahl (ONKz).
 *
 * @return z.B. "0711" fuer Stuttgart// ww w.ja va  2  s .  c  o m
 */
public String getVorwahl() {
    String[] parts = this.getCode().trim().split("[ /-]|(\\(0\\))");
    String vorwahl = parts[0];
    if (vorwahl.startsWith("+")) {
        vorwahl = StringUtils.isBlank(parts[1]) ? parts[2] : parts[1];
    }
    vorwahl = RegExUtils.removeAll(vorwahl, "[ \t+-/(\\(\\))]");
    if (vorwahl.startsWith("0")) {
        return vorwahl;
    }
    return "0" + vorwahl;
}

From source file:de.jfachwert.net.Telefonnummer.java

/**
 * Stellt eine Telefonnummer in verkuerzter Schreibweise ohne Leerzeichen
 * und Trennzeichen dar.// w  w w .  j  a  v a  2s  .co  m
 *
 * @return z.B. "+49301234567"
 */
public String toShortString() {
    return RegExUtils.removeAll(getCode(), "[ \t+-/]|(\\(0\\))");
}

From source file:com.erudika.scoold.utils.ScooldUtils.java

public String sanitizeQueryString(String query, HttpServletRequest req) {
    String qf = getSpaceFilteredQuery(req);
    String defaultQuery = "*";
    String q = StringUtils.trimToEmpty(query);
    if (qf.isEmpty() || qf.length() > 1) {
        q = q.replaceAll("[\\*\\?]", "").trim();
        q = RegExUtils.removeAll(q, "AND");
        q = RegExUtils.removeAll(q, "OR");
        q = RegExUtils.removeAll(q, "NOT");
        q = q.trim();/*w  ww. j  ava  2  s  . co m*/
        defaultQuery = "";
    }
    if (qf.isEmpty()) {
        return defaultQuery;
    } else if ("*".equals(qf)) {
        return q;
    } else {
        if (q.isEmpty()) {
            return qf;
        } else {
            return qf + " AND " + q;
        }
    }
}