illegal string body character after dollar sign

前端 未结 4 1255
既然无缘
既然无缘 2020-12-25 14:33

if i define a groovy variable

def x = \"anish$\"

it will throw me error, the fix is

def x = \"anish\\$\"

4条回答
  •  我在风中等你
    2020-12-25 15:15

    The solution from tim_yates does not work in some contexts, e.g. in a Jasper report. So if still everything with a $ sign wants to be interpreted as some variable (${varX}), e.g. in

    "xyz".replaceAll("^(.{4}).{3}.+$", "$1...")
    

    then simply make the dollar sign a single concatenated character '$', e.g.

    "xyz".replaceAll("^(.{4}).{3}.+"+'$', '$'+"1...")
    

提交回复
热议问题