Java Regex Pattern Split Example
Chapter:
Regular Expression
Last Updated:
21-06-2016 18:59:26 UTC
Program:
/* ............... START ............... */
import java.util.regex.Pattern;
public class JavaRegexPatternSplit {
public static void main(String args[]) {
String statement = "a b c d e f g h i j k l";
String splitPattern = "e|c|a|a|(a b d e)|(b c e)";
Pattern p = Pattern.compile(splitPattern);
String[] tokens = p.split(statement);
for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
}
}
/* ............... END ............... */
Output
Notes:
-
The java.lang.String.split(String regex) method splits this string around matches of the given regular expression.
- Syntax : public String[] split(String regex).
Tags
Java Regex Pattern Split, Regular Expression