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 removeTags(String string) {
    if (string == null || string.length() == 0) {
        return string;
    }/*from   w  w  w  .  j  a va2  s . c  om*/

    Matcher m = REMOVE_TAGS.matcher(string);
    return m.replaceAll("");
}

From source file:Main.java

private static String sanitizeString(String srcString) {
    Matcher matcher = pattern.matcher(srcString);
    String res = matcher.replaceAll("_");
    return res; // Number starts allowed rightnow
}

From source file:Main.java

public static String replaceSpaces(String url) {
    if (!url.isEmpty()) {
        url = url.trim();// www . j av  a2 s. c o  m
        if (url.contains(" ")) {
            Matcher spaces = SPACE.matcher(url);
            url = spaces.replaceAll("%20");
        }
    }
    return url;
}

From source file:Main.java

public static String a(Context var0) {
    String var1 = var0.getPackageName();
    String var3;

    try {/* w ww .  jav a2  s  .  c o m*/
        ApplicationInfo var2 = var0.getPackageManager().getApplicationInfo(var1, PackageManager.GET_META_DATA);
        var3 = var2.metaData.getString("TencentMapSDK");
        if (!TextUtils.isEmpty(var3)) {
            String var4 = "[&=]";
            Pattern var5 = Pattern.compile(var4);
            Matcher var6 = var5.matcher(var3);
            var3 = var6.replaceAll("");
        }
    } catch (PackageManager.NameNotFoundException var7) {
        var3 = "GRYBZ-ACPWV-UIGPO-U2SRZ-KRYB6-7VFTU";
    }

    return var3;
}

From source file:com.aistor.common.utils.StringUtils.java

/**
 * ?HTML//  w  ww  .j  av a  2  s.co  m
 */
public static String replaceHtml(String html) {
    String regEx = "<.+?>";
    Pattern p = Pattern.compile(regEx);
    Matcher m = p.matcher(html);
    String s = m.replaceAll("");
    return s;
}

From source file:Main.java

public static double parseCoordinate(CharSequence string) {
    int sign = 1;
    final Matcher negsignMatcher = PAT_NEGSIGN.matcher(string);
    if (negsignMatcher.find()) {
        sign = -1;//w ww .j a v  a 2 s.co  m
    }

    final Matcher signMatcher = PAT_SIGN.matcher(string);
    string = signMatcher.replaceAll("");

    final Matcher dmsMatcher = PAT_COORD_COMPONENT.matcher(string);
    double degrees = 0.0;
    for (double scale = 1.0; scale <= 3600.0 && dmsMatcher.find(); scale *= 60.0) {
        degrees += Double.parseDouble(dmsMatcher.group(1)) / scale;
    }
    return sign * degrees;
}

From source file:net.wastl.webmail.ui.html.JavaScriptFilter.java

public static String apply(String s) {
    if (!initialized) {
        init();/*w  w  w .ja va2s  . c o m*/
    }
    String retval = s;
    for (int i = 0; i < filter.length; i++) {
        Matcher m = filter[i].matcher(retval);
        retval = m.replaceAll(substitution[i]);
    }
    return retval;
}

From source file:Main.java

/**
 * @param str/*from   w  w  w . jav a  2s  . co  m*/
 * @return String.
 */
public static String multiSpace2singleSpace(String str) {
    Pattern pattern;
    Matcher matcher;
    pattern = Pattern.compile("[\\s]+");
    matcher = pattern.matcher(str);
    return matcher.replaceAll(" ");
}

From source file:Main.java

public static String encode(String str) {

    if (str == null) {
        return null;
    }/*from ww  w. j  av  a2  s  . c o  m*/

    Matcher gtMatcher = gt.matcher(str);
    if (gtMatcher.matches()) {
        str = gtMatcher.replaceAll("&gt;");
    }
    Matcher ltMatcher = lt.matcher(str);
    if (ltMatcher.matches()) {
        str = ltMatcher.replaceAll("&lt;");
    }
    Matcher quotMatcher = quot.matcher(str);
    if (quotMatcher.matches()) {
        str = quotMatcher.replaceAll("&quot;");
    }
    Matcher ampMatcher = amp.matcher(str);
    if (ampMatcher.matches()) {
        str = ampMatcher.replaceAll("&amp;");
    }

    return str;
}

From source file:net.wastl.webmail.ui.html.Fancyfier.java

public static String apply(String s) {
    if (regs == null) {
        init();/* w  w w  . j ava 2 s.  c  o m*/
    }
    String retval = s;
    for (int i = 0; i < regs.length; i++) {
        Matcher m = regs[i].matcher(retval);
        retval = m.replaceAll(repls[i]);
        //retval=regs[i].substituteAll(retval,repls[i]);
    }
    return retval;
}