Let's say I have the following string :
String in = "A xx1 B xx2 C xx3 D";
I want the result :
String out = "A 1 B 4 C 9 D";
I would like to do it a way resembling the most :
String out = in.replaceAll(in, "xx\\d",
new StringProcessor(){
public String process(String match){
int num = Integer.parseInt(match.replaceAll("x",""));
return ""+(num*num);
}
}
);
That is, using a string processor which modifies the matched substring before doing the actual replace.
Is there some library already written to achieve this ?