Reputation: 1758
Simple question:
Which is the most efficient way of performing a substituion like:
"Some tekst with a link like this <ref>linktekst</ref>"
To
"Some tekst with a link like this <a href="linktekst">linktekst</a>"
In groovy?
There can easily be more than one tag in the text, that should be substituted, and linktext is of course the body of the <ref>
tag.
Upvotes: 2
Views: 1145
Reputation: 171194
You can use String.replaceAll
:
def s = "Some tekst with a link like this <ref>linktekst</ref> and <ref>link2</ref>"
s = s.replaceAll "<ref>(.+?)</ref>", '<a href="$1">$1</a>'
Upvotes: 2