简单问题:
这是执行替代的最有效方式,如:
"Some tekst with a link like this <ref>linktekst</ref>"
要
"Some tekst with a link like this <a href="linktekst">linktekst</a>"
在groovy?
文本中很容易有多个标记,应该替换, linktext 当然是<ref>
标记的主体。
答案 0 :(得分:2)
您可以使用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>'