List of usage examples for java.util.regex Pattern split
public String[] split(CharSequence input)
From source file:Main.java
public static void main(String[] args) { String pattern = "[,\\s]+"; String colours = "Red,White, Blue Green Yellow, Orange"; Pattern splitter = Pattern.compile(pattern); String[] result = splitter.split(colours); for (String colour : result) { System.out.println("Colour = \"" + colour + "\""); }//from w w w . j av a 2 s.co m }
From source file:MainClass.java
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]); }// w w w. j a v a 2 s .c o m }
From source file:MainClass.java
public static void main(String args[]) { Pattern pat = Pattern.compile("[ ,.!]"); String strs[] = pat.split("www.java2s.com java javascript API example."); for (int i = 0; i < strs.length; i++) System.out.println("Next token: " + strs[i]); }
From source file:PatternSplit.java
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;/*from ww w. j av a 2 s. co m*/ 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]); } }
From source file:SplitDemo2.java
public static void main(String[] args) { Pattern p = Pattern.compile(REGEX); String[] items = p.split(INPUT); for (String s : items) { System.out.println(s);/*from w w w . j a v a2s . c o m*/ } }
From source file:SplitTest.java
public static void main(String[] argv) { Pattern p = Pattern.compile(REGEX); String[] items = p.split(INPUT); for (int i = 0; i < items.length; i++) { System.out.println(items[i]); }//from w w w . j ava2 s . com }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile(" "); String tmp = "this is a test"; String[] tokens = p.split(tmp); for (int i = 0; i < tokens.length; i++) { System.out.println(tokens[i]); }//from w w w . j av a 2 s . c om }
From source file:PatternSplitExample.java
public static void main(String args[]) { Pattern p = Pattern.compile(" "); String tmp = "this is the String I want to split up"; String[] tokens = p.split(tmp); for (int i = 0; i < tokens.length; i++) { System.out.println(tokens[i]); }/*from w w w. j a v a 2 s . c o m*/ }
From source file:org.apache.lucene.pinyin.dwarf.PinyinTokenizer.java
public static void main(String[] args) { String string = "?"; // System.out.println(getpinyin(string)); Pattern pattern = Pattern.compile("[\\pP\\s]"); String[] arrStrings = pattern.split(string); for (int i = 0; i < arrStrings.length; i++) { String string2 = arrStrings[i]; System.out.println(filterkeyWords(string2)); }//from w ww. j a v a2s . com }
From source file:WordCount.java
public static void main(String args[]) throws Exception { String filename = "WordCount.java"; // Map File from filename to byte buffer FileInputStream input = new FileInputStream(filename); FileChannel channel = input.getChannel(); int fileLength = (int) channel.size(); MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength); // Convert to character buffer Charset charset = Charset.forName("ISO-8859-1"); CharsetDecoder decoder = charset.newDecoder(); CharBuffer charBuffer = decoder.decode(buffer); // Create line pattern Pattern linePattern = Pattern.compile(".*$", Pattern.MULTILINE); // Create word pattern Pattern wordBreakPattern = Pattern.compile("[\\p{Punct}\\s}]"); // Match line pattern to buffer Matcher lineMatcher = linePattern.matcher(charBuffer); Map map = new TreeMap(); Integer ONE = new Integer(1); // For each line while (lineMatcher.find()) { // Get line CharSequence line = lineMatcher.group(); // Get array of words on line String words[] = wordBreakPattern.split(line); // For each word for (int i = 0, n = words.length; i < n; i++) { if (words[i].length() > 0) { Integer frequency = (Integer) map.get(words[i]); if (frequency == null) { frequency = ONE;/* w w w . j av a 2s.c o m*/ } else { int value = frequency.intValue(); frequency = new Integer(value + 1); } map.put(words[i], frequency); } } } System.out.println(map); }