简单问题:
这是执行替换的最有效方法,例如:
"Some tekst with a link like this <ref>linktekst</ref>"
至
"Some tekst with a link like this <a href="linktekst">linktekst</a>"
时髦吗?
文本中很容易有多个标签,应该被替换,linktext 当然是 <ref>
的正文标签。
最佳答案
您可以使用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>'
关于string - Groovy 中使用 "body"进行高效字符串替换策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10717898/