---
title: "Groovy字符串替换一例"
author: "boogie"
date: "2008-06-12T17:11:29Z"
tags: []
slug: "groovy"
draft: false
lastmod: "2008-06-12T17:11:29Z"
id: 202557
url: "https://boogie.iteye.com/blog/202557"
---

将param替换成paramValue

 

```
def queryContent = "select * from query where id=${param}"
def regex = '\\$\\{param\\}'
def matcher = (queryContent =~ /${regex}/)
queryContent = matcher.replaceAll('paramValue')
```

 

参考： [http://docs.codehaus.org/display/GROOVY/Tutorial+5+-+Capturing+regex+groups](http://docs.codehaus.org/display/GROOVY/Tutorial+5+-+Capturing+regex+groups)