An example of the string is 1-2.5.6/8/3.4?1=f-g&e=d&h=i
and in JavaScript the code p = p.replace(new RegExp('\\b' + '\\w+' + '\\b', 'g'), k[c])
will replace the characters 1, 2, 5, 6, 8, 3, 4, 1, f, g, e, d, h, and i with their respective string that is returned from the k[c], a function which just takes the character from the string and returns another value from a dictionary. I am trying to implement the same thing in Java, but some of the replaced characters have characters like 1, 2, 5, 6, 8, etc. So delivery45-2.5.6/8/3.4?1=f-g&e=d&h=i
will turn into STRINGelivery45-2.5.6/8/3.4?1=f-g&e=d&h=i
. Is there a to implement the same thing in Java as it does in JavaScript?
Here is what I am currently using in Java:
Pattern pattern = Pattern.compile("\\b\\w+\\b");
Matcher matcher = pattern.matcher(p);
while (matcher.find()) {
String matchedString = matcher.group();
String replacementString = z.apply(String.valueOf(matchedString));
p = p.replace(matchedString, replacementString);
}
p being the original string, and z acting like k[c].
The result ends up being something like STRING_tliv56287592ry45-2.5.6/8/3.4?1=f-g&e=d&h=i
which goes until it can't replace anymore.