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 trimFirstAndLastNewline(String source) {
    source = source.replaceAll("^(\\\\n)*", "");
    source = source.replaceAll("(\\\\n)*$", "");
    return source;
}

From source file:Main.java

public static String breadcrumbsToPath(String breadcrumbs) {
    return breadcrumbs.replaceAll("\\s", "");
}

From source file:Main.java

public static String escapeURI(String uri) {
    uri = uri.replaceAll("&", "&");
    uri = uri.replaceAll("'", "'");
    uri = uri.replaceAll("\"", """);
    uri = uri.replaceAll(">", ">");
    uri = uri.replaceAll("<", "&lt;");
    return uri;/*from  www  . jav  a2 s  .  co m*/
}

From source file:Main.java

public static int getWordCountRegex(String s) {

    String t = s.replaceAll("[^\\x00-\\xff]", "**");
    int length = t.length();
    return length;
}

From source file:Main.java

public static String generateUpDirectoriesFromPath(String baseDir) {
    baseDir = baseDir.replaceAll("[^/]*[^./][^/]*|[.]+[^/]", "..");
    return baseDir;
}

From source file:Main.java

public static String camelToLowerCase(final String camel) {
    return camel.replaceAll("(\\p{Ll})(\\p{Lu})", "$1_$2").toLowerCase();
}

From source file:Main.java

public static String escapeXml(String str) {
    str = str.replaceAll("&", "&amp;");
    str = str.replaceAll("<", "&lt;");
    str = str.replaceAll(">", "&gt;");
    str = str.replaceAll("\"", "&quot;");
    str = str.replaceAll("'", "&apos;");
    return str;//w w w . j ava 2s . c o  m
}

From source file:Main.java

public static String toXHTML(String html) {
    html = html.replaceAll("(?s)<script>.*?</script>", "<!-- removed scripts --!>");
    final Document document = Jsoup.parse(html);
    document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
    return document.html();
}

From source file:Main.java

public static String fixText(String input) {
    input = input.replaceAll("&amp;", "&");
    input = input.replaceAll("&#039;", "'");
    input = input.trim();/*from  w w w . j  a  va2s .com*/
    return input;
}

From source file:Main.java

private static String escapePath(String path) {
    String ep = path;
    ep = ep.replaceAll("\\!", "!!");
    ep = ep.replaceAll("_", "!_");
    ep = ep.replaceAll("%", "!%");
    return ep;//from w  w w  .  ja va  2  s . c  o  m
}