For a quick sample, I have the following string:
String s = "hey.there.man.${a.a}crazy$carl${a.b}jones
I also have the following method:
private String resolveMatchedValue(String s) {
if(s.equals("a.a")) {
return "A";
else if(s.equals("a.b")) {
return "Wallet";
else if(.....
....
}
My pattern would be
Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}");
So for every substring in s that matches ${.*} I want there to be a call to the resolveMatchedValue method and it should be replaced with that. So ideally after the regex process s should be
s = "hey.there.man.Acrazy$carl$Walletjones
I've looked at similar solutions but nothing that dynamically replaces the matched values based on the matched value, and have not been able to get it to work
Aucun commentaire:
Enregistrer un commentaire