Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping in groovy

I need a help in escaping in groovy

I have some string in text file like this #$commonTomcat620.max_threads$# These value i have to replace in runTime.

I used following code:

    def str = "#\$commonTomcat620.max_threads\$#"
    fileContents = fileContents.replaceAll("${str}","100");

This str is printin the values as #$commonTomcat620.max_threads$#. but not replacing in file. I tried withOut #$ . it is working.

Thanks.

like image 476
Jeevi Avatar asked Oct 29 '12 12:10

Jeevi


1 Answers

You have a couple of options to escape the dollar sign:

This works (with dollar-slashy strings):

def str = $/#\$$commonTomcat620.max_threads\$$#/$

Or this (with single quote strings):

def str = '#\\$commonTomcat620.max_threads\\$#'

Other options probably exist too

like image 153
tim_yates Avatar answered Sep 21 '22 09:09

tim_yates