other 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. To perform a replacement call replace(someInput):
System.out.print(perlExpressionReplacer.replace("All your base ")); System.out.println(myVeryOwnReplacer.replace("are belong to us")); //result: "[All] [your] [base] [are] [belong] [to] [us]"
@see Substitution
@see PerlSubstitution
@see Replacer#Replacer(jregex.Pattern,jregex.Substitution)