1 57 import java.util.*; 58 import org.apache.oro.text.regex.*; 59 import org.apache.oro.text.awk.*; 60 61 69 public final class splitExample { 70 71 88 public static final void main(String args[]) { 89 int limit, i; 90 String regularExpression, input; 91 Vector results; 92 Pattern pattern = null; 93 PatternMatcher matcher; 94 PatternCompiler compiler; 95 96 if(args.length < 2) { 98 System.err.println("Usage: splitExample regex input [split limit]"); 99 System.exit(1); 100 } 101 102 regularExpression = args[0]; 103 input = args[1]; 104 105 if(args.length > 2) 106 limit = Integer.parseInt(args[2]); 107 else 108 limit = Util.SPLIT_ALL; 109 110 compiler = new AwkCompiler(); 112 matcher = new AwkMatcher(); 113 114 try { 117 pattern = compiler.compile(regularExpression); 118 System.out.println("split regex: " + regularExpression); 119 } catch(MalformedPatternException e){ 120 System.err.println("Bad pattern."); 121 System.err.println(e.getMessage()); 122 System.exit(1); 123 } 124 125 System.out.println("split results: "); 127 results = Util.split(matcher, pattern, input, limit); 128 for(i = 0; i < results.size(); i++){ 129 System.out.println("item " + i + ": " + (String )results.elementAt(i)); 130 } 131 } 132 } 133 | Popular Tags |