Replacer.java | Class | The Replacer class suggests some methods to replace occurences of a pattern
either by a result of evaluation of a perl-like expression, or by a plain string,
or according to a custom substitution model, provided as a Substitution interface implementation.
A Replacer instance may be obtained either using Pattern.replacer(...) method, or by constructor:
Pattern p=new Pattern("\\w+");
Replacer perlExpressionReplacer=p.replacer("[$&]");
//or another way to do the same
Substitution myOwnModel=new Substitution(){
public void appendSubstitution(MatchResult match,TextBuffer tb){
tb.append('[');
match.getGroup(MatchResult.MATCH,tb);
tb.append(']');
}
}
Replacer myVeryOwnReplacer=new Replacer(p,myOwnModel);
The second method is much more verbose, but gives more freedom. |