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 void main(String[] argv) {
    String s = " this is a test ";

    s.replaceAll("^\\s+", "");
    System.out.println(">" + s + "<");
}

From source file:Main.java

public static void main(String[] args) {
    String input = "4 5 \\asd";
    input = input.replaceAll("\\\\[a-zA-Z0-9]*", "");
    System.out.println(input);/*from  ww w . j  av  a 2s.c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    String text = "     a     ";

    text = text.replaceAll("\\s+$", "");
    System.out.println("Text: " + text);
}

From source file:Main.java

public static void main(String[] args) {
    String text = "     t     ";

    text = text.replaceAll("^\\s+", "");
    System.out.println("Text: " + text);
}

From source file:Main.java

public static void main(String[] args) {
    String input = "2x^4 - 45y^4";
    input = input.replaceAll("\\D", " ");
    String[] parts = input.split("\\W+");

    System.out.println(Arrays.toString(parts));
}

From source file:Main.java

public static void main(String[] args) {

    String str = "HELLO WORLD {IMAGE:abcd}";
    str = str.replaceAll("\\{IMAGE:abcd\\}", "defg");
    System.out.println(str);/*  w  ww. j  a v a2s. c  om*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String str = "Abc abc";

    String result = str.replaceAll("(?i)abc", "DEF");

    System.out.println("After replacement:\n" + "   " + result);

}

From source file:Main.java

public static void main(String[] args) {
    String text = "a b c e a b";

    System.out.println(text.replaceAll("(?:a b)+", "x y"));

}

From source file:Main.java

public static void main(String args[]) {

    String str = "This is a test.";

    System.out.println(str.replaceAll("is", "are"));
}

From source file:Main.java

public static void main(String[] args) {
    String xml = "<a>test 1</a>    <b>test 2</b> ";
    String out = xml.replaceAll(">\\s+<", "><");
    System.out.println(xml);//  ww w. ja v  a2  s  .  c  o  m
    System.out.println(out);
}