string - Groovy 中使用 "body"进行高效字符串替换策略

标签 string performance groovy replace

简单问题:

这是执行替换的最有效方法,例如:

"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/

相关文章:

grails - 当 `grails-app/views` 目录中不存在文件时,Grails 如何渲染 View ?

grails - Grails 应用程序的初始数据

string - TRIM RTRIM LTRIM 性能

string - 将不同长度的字符串传递给 Fortran 中的函数

apache-flex - 在 Flex 中实现定时器循环是不是一个坏主意?

java - 使用 hashmap 改进词频计数

Tomcat 记录 http 请求并调用 java 代码

C:使用 scanf() 函数而不是 gets

python - 如何在两个文本文件中查找单词

python - 如何将图像集合中的像素(R、G、B)映射到不同的像素颜色值索引?