Monday, January 15, 2007

nice regex util class, replaceAll

elliotth.blogspot.com/java-implementation-of-rubys-gsub.html

Here is an example of what this does:
String result = new Rewriter("([0-9]+) US cents") {
public String replacement() {
long dollars = Long.parseLong(group(1))/100;
return "$" + dollars;
}
}.rewrite("5000 US cents");
System.out.println(result);

prints>> $50

nice!

No comments:

Post a Comment