Matcher.replaceAll Method Example

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Matcher.replaceAll Method Example

This Java example program shows how to use Matcher.replaceAll Method.

[edit] Java Source Code

  • Package: example.matcher
  • File: MatcherReplaceAllExample.java
package example.matcher;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class MatcherReplaceAllExample {
    public static void main(String args[]) {
	Pattern p = Pattern.compile("(i|I)ce");
 
	// create the candidate String
	String candidateString = "I love ice. Ice is my favorite. Ice Ice Ice.";
 
	Matcher matcher = p.matcher(candidateString);
	String tmp = matcher.replaceAll("Java");
 
	System.out.println(tmp);
 
    }
}

[edit] What Result You Can Get

Run the program, you will get:

I love Java. Java is my favorite. Java Java Java.

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.

http://www.ase2009.com/ online casino 132 http://www.hellzyea.com/health health insurance 8DDD http://www.yourautoinsurancesite.com/ auto insurance quotes 135811 http://www.makemeasammich.com/ auto insurance mcnxu

[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools