I’ve got a regex that’s matching a given pattern(obviously, thats what regex’s do) and replacing that pattern with an anchor tag and including a captured group. That part is working lovely.
String substituted = content.asString().replaceAll("\\[{2}((?:.)*?)\\]{2}",
"<a href=\"#!p\\:$1\">$1</a>");
What I can’t figure out is how to url encode the captured group before using it in the href attribute.
Example inputs
[[a]][[a b]][[a&b]]
desired outputs
<a href="a">a</a><a href="a+b">a b</a><a href="a%26b">a&b</a>
Is there any way to do this? I haven’t found anything that looks useful yet, though once I ask I usually find an answer.
Sure ‘nough, found my answer.
Started with the code from Matcher.appendReplacement
Pure java:
GWT: