PatternSplit.java Example

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - PatternSplit.java Example

This Java example program introduces PatternSplit.java example.

[edit] Java Source Code

  • Package: example.pattern
  • File: PatternSplit.java
package example.pattern;
 
import java.util.regex.Pattern;
 
public class PatternSplit {
    public static void main(String args[]) {
 
	String statement =
		"I will not compromise. I will not " + "cooperate. There will be no concession, no conciliation, no "
			+ "finding the middle ground, and no give and take.";
 
	String tokens[] = null;
	String splitPattern = "compromise|cooperate|concession|" + "conciliation|(finding the middle ground)|(give and take)";
 
	Pattern p = Pattern.compile(splitPattern);
 
	tokens = p.split(statement);
 
	System.out.println("REGEX PATTERN:\n" + splitPattern + "\n");
 
	System.out.println("STATEMENT:\n" + statement + "\n");
 
	System.out.println("TOKENS:");
	for (int i = 0; i < tokens.length; i++) {
	    System.out.println(tokens[i]);
	}
    }
}

[edit] What Result You Can Get

Run the program, you will get:

REGEX PATTERN:
compromise|cooperate|concession|conciliation|(finding the middle ground)|(give and take)

STATEMENT:
I will not compromise. I will not cooperate. There will be no concession, no conciliation, no finding the middle ground, and no give and take.

TOKENS:
I will not 
. I will not 
. There will be no 
, no 
, no 
, and no 
.

[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