You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by ravi <ra...@htinc.com> on 2003/05/07 21:35:36 UTC
Problem with Perl5Substitution
I have tried to use Perl5Substitution class to do the following
substitution.
All I wanted to do is to insert a blank space before some special
strings like 's,'ll in the given string. This is the piece of the code
that I used to do this.
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
match = "('s|'d|'m|'ll|'re|'ve|n't)([^A-Za-z0-9])";
sub = " $&";
input = "let's hope he'll do the best";
Pattern pattern = null;
Perl5Substitution substitution = new Perl5Substitution(sub);
try {
pattern = compiler.compile(match);
}
catch(MalformedPatternException e){
System.err.println("Bad pattern.");
System.exit(1);
}
input=Util.substitute(matcher,pattern,substitution,input,Util.SUBSTITUTE
_ALL);
But instead of returning "let 's hope he 'll do the best", it returned
me "let $&hope he $&do the best". i.e. It's just replacing the match
string with $& instead of inserting a blank space before it...
Can somebody help me out?
Thanks,
Ravi.