Example usage for java.util.regex Matcher replaceAll

List of usage examples for java.util.regex Matcher replaceAll

Introduction

In this page you can find the example usage for java.util.regex Matcher replaceAll.

Prototype

public String replaceAll(Function<MatchResult, String> replacer) 

Source Link

Document

Replaces every subsequence of the input sequence that matches the pattern with the result of applying the given replacer function to the match result of this matcher corresponding to that subsequence.

Usage

From source file:Main.java

public static String getDigital(String str) {
    String regEx = "[^0-9]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.replaceAll("").trim();
}

From source file:Main.java

public static String replaceCN(String str) {
    String regEx = "[\\u4e00-\\u9fa5]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.replaceAll("");
}

From source file:Main.java

private static String getStringNum(String str) {
    String regEx = "[^0-9]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.replaceAll("").trim();
}

From source file:Main.java

public static String stringFilter(String str) throws PatternSyntaxException {
    String regEx = "[^\\u4E00-\\u9FA5]";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(str);
    return m.replaceAll("").trim();
}

From source file:Main.java

public static String replaceBlankWithSpace(String str) {
    String dest = "";
    if (str != null) {
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }//from  ww w  . j av a 2s . c om
    return dest;
}

From source file:Main.java

public static String replaceBlank(String str) {
    String dest = "";
    if (str != null) {
        Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }/*  w  w  w .ja v a 2 s . co m*/
    return dest;
}

From source file:Main.java

public static String replaceBlank(String str) {
    String dest = "";
    if (str != null) {
        Pattern p = Pattern.compile("\\s*");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }/*from   w  ww  .j  a v a  2  s  .c o  m*/
    return dest;
}

From source file:Main.java

public static String replaceSymbol(String str) {
    String dest = "";
    if (str != null) {
        // Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(str);
        dest = m.replaceAll("");
    }//w ww  .  ja  v a2  s .  c  o  m
    return dest;
}

From source file:Main.java

public static String replace(String string) {
    Pattern pattern = Pattern.compile(".*?");
    Matcher matcher = pattern.matcher(string);
    return matcher.replaceAll("$1").trim();
}

From source file:Main.java

public static String removeCommas(String text) {
    Pattern p = Pattern.compile("(\\d+),(\\d\\d\\d$|\\d\\d\\d\\D)");
    String oldText;//from   w w  w. j  a  va2s .  c  o m
    do {
        oldText = text;
        Matcher m = p.matcher(text);
        text = m.replaceAll("$1$2");
    } while (oldText.equalsIgnoreCase(text) == false);
    return text;
}