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 stripHTML(String htmlText) {
    // Replace break
    String processed_str = htmlText.replaceAll("\\<br\\>", "");
    // Remove HTML
    processed_str = processed_str.replaceAll("\\<.*?>", "");
    // Remove () [] and their content
    processed_str = processed_str.replaceAll("\\[.*?\\]", "");
    // Remove the XML special character
    processed_str = processed_str.replaceAll("\\[.*?\\]", "");
    return processed_str.trim();
}

From source file:net.link.eu.vat.client.util.VATUtil.java

/**
 * Cleans a VAT number, ready to send to EU VAT service.
 *
 * E.g.: "BE 0446.495.156" becomes "0446495156".
 *
 * @param vatNumber the VAT number./*from   w w w.  j a  va  2  s  . com*/
 *
 * @return the cleaned VAT number.
 */
@NotNull
public static String cleanEnterpriseNumber(@NotNull String vatNumber) {

    return vatNumber.replaceAll("[^0-9]+", ""); //Remove all non-digits
}

From source file:Main.java

/**
 * to get the Number of Chinese Characters in the input String.
 * @param str/*from  w w  w.  j a v a2s  . c  o  m*/
 * @return the Number of Chinese Characters
 */
public static int getChineseCharNum(String str) {
    String regEx = "[\u4e00-\u9fa5]";
    String tem = str.replaceAll(regEx, "aa");
    int n = tem.length() - str.length();
    return n;
}

From source file:Main.java

/**
 * Since "&" in menu text has special meaning, we must escape it before
 * displaying./*from w  ww  .  j  av  a  2  s. c  o m*/
 * 
 * @param src
 *            Source text.
 * @return Escaped text.
 */
public static String getEscapedMenuItemText(String src) {
    if (src != null && src.indexOf('&') != -1) {
        src = src.replaceAll("\\&", "&&"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    return src;
}

From source file:Main.java

public static String encode(String str) {

    if (str == null) {
        return null;
    }/*  w w w.j  a va2  s .c o  m*/

    str = str.replaceAll(">", "&gt;");
    str = str.replaceAll("<", "&lt;");
    str = str.replaceAll("\"", "&quot;");
    str = str.replaceAll("&", "&amp;");

    return str;
}

From source file:Main.java

private static String clearLastSpace(String txt) {
    if (TextUtils.isEmpty(txt)) {
        return txt;
    }/*from   ww  w  . j  ava2  s  .c o m*/

    return txt.replaceAll("(&#160;)*$", "");
}

From source file:Main.java

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

From source file:Main.java

public static String trimmy(String str) {
    String dest = "";
    if (str != null) {
        str = str.replaceAll("-", "");
        str = str.replaceAll("\\+", "");
        dest = str;/*from   w w w.jav  a  2  s.  co  m*/
    }
    return dest;
}

From source file:Main.java

/**
 * Replace all instances of &lt;, &gt;, &amp;, &apos; &quot; with the XML
 * safe strings./*from  ww  w  . j a  v a 2s.c  om*/
 *
 * @param string to convert
 * @return converted String
 */
public static String convertIllegalCharacters(String string) {
    String newString = new String();
    newString = string.replaceAll("<", "&lt;");
    newString = newString.replaceAll(">", "&gt;");
    newString = newString.replaceAll("&", "&amp;");
    newString = newString.replaceAll("'", "&apos;");
    newString = newString.replaceAll("\"", "&quot;");
    return newString;
}

From source file:com.vamonossoftware.core.TextUtil.java

/**
 * @deprecated Use org.apache.commons.lang.StringEscapeUtils.escapeHtml()
 * @see /*from  w ww.j  a va2 s .  com*/
 */
public static String escapeHtml(String in) {
    String result = in.replaceAll("<", "&lt;");
    result = result.replaceAll(">", "&gt;");
    return result;
}