s "[The] [quick] [brown] [fox] [jumped] [over] [the] [lazy] [dog]" Pattern swap=new Pattern("(fox|dog)(.*?)(fox|dog)"); System.out.println(swap.replacer("$3$2$1").replace(text)); //prints "The quick brown dog jumped over the lazy fox" Pattern scramble=new Pattern("(\\w+)(.*?)(\\w+)"); System.out.println(scramble.replacer("$3$2$1").replace(text)); //prints "quick The fox brown over jumped lazy the dog"
@param expr a perl-like expression, the "$&" and "${&}" standing for whole match, the "$N" and "${N}" standing for group#N, and "${Foo}" standing for named group Foo.
@see Replacer
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.