在groovy逃脱

Jee*_*evi 10 groovy escaping

我需要一个帮助逃脱groovy

我在这样的文本文件中有一些字符串#$ commonTomcat620.max_threads $# 这些值我必须在runTime中替换.

我使用以下代码:

    def str = "#\$commonTomcat620.max_threads\$#"
    fileContents = fileContents.replaceAll("${str}","100");
Run Code Online (Sandbox Code Playgroud)

这个str打印的值是#$ commonTomcat620.max_threads $#.但不是替换文件.我试过withOut#$.这是工作.

谢谢.

tim*_*tes 14

你有几个选择来逃避美元符号:

这适用(使用美元 - 字符串):

def str = $/#\$$commonTomcat620.max_threads\$$#/$
Run Code Online (Sandbox Code Playgroud)

或者这个(带单引号字符串):

def str = '#\\$commonTomcat620.max_threads\\$#'
Run Code Online (Sandbox Code Playgroud)

其他选项也可能存在