1 57 58 import org.apache.oro.text.regex.*; 59 import org.apache.oro.text.awk.*; 60 61 69 public final class substituteExample { 70 71 93 public static final void main(String args[]) { 94 int limit, interps, i; 95 PatternMatcher matcher = new AwkMatcher(); 96 Pattern pattern = null; 97 PatternCompiler compiler = new AwkCompiler(); 98 String regularExpression, input, result; 99 Substitution sub; 100 101 if(args.length < 3) { 103 System.err.println("Usage: substituteExample regex substitution " + 104 "input [sub limit]"); 105 System.exit(1); 106 } 107 108 limit = Util.SUBSTITUTE_ALL; 109 110 regularExpression = args[0]; 111 sub = new StringSubstitution(args[1]); 112 input = args[2]; 113 114 if(args.length > 3) 115 limit = Integer.parseInt(args[3]); 116 117 try { 118 pattern = compiler.compile(regularExpression); 119 System.out.println("substitute regex: " + regularExpression); 120 } catch(MalformedPatternException e){ 121 System.err.println("Bad pattern."); 122 System.err.println(e.getMessage()); 123 System.exit(1); 124 } 125 126 result = Util.substitute(matcher, pattern, sub, input, limit); 128 System.out.println("result: " + result); 129 } 130 } 131 | Popular Tags |