# Copy Task - Filtering With Token-less String Replacement

**URL:** <https://discuss.gradle.org/t/copy-task-filtering-with-token-less-string-replacement/3221>\
**Category:** Old Forum Archive\
**Created:** [December 15, 2011, 3:42am UTC](https://discuss.gradle.org/t/copy-task-filtering-with-token-less-string-replacement/3221 "2011-12-15T03:42:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghillert](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ghillert/32/669_2.png) [@ghillert](https://discuss.gradle.org/u/ghillert)\
**Post date:** [December 15, 2011, 3:42am UTC](https://discuss.gradle.org/t/copy-task-filtering-with-token-less-string-replacement/3221/1 "2011-12-15T03:42:00Z")

</div>

Hi,

When using the copy task - How can I filter/expand and do pure String replacement, without using either Groovy’s SimpleTemplateEngine’s format ${stringToReplace} or Ant’s ReplaceToken format @StringToReplace@?

I basically have multiple files that need to be filtered using raw Strings, without marking those Strings with Tokens, e.g. a file may contain

“…lorem ipsum replace-this-string blubba foo bar…”

and ‘replace-this-string’ needs to be replaced with something else.

I saw some mentioning that I can use other ‘java.io.FilterReader’ implementations and I guess maybe a custom one may be necessary. Anyway, I could not find any further examples for my use-case and I am admittedly still learning Gradle - So for any pointers I would be grateful.

Thanks!

Cheers,

Gunnar

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [December 15, 2011, 4:04am UTC](https://discuss.gradle.org/t/copy-task-filtering-with-token-less-string-replacement/3221/2 "2011-12-15T04:04:00Z")

</div>

One option is to use the free-form filter method:

```gradle
task copy(type: Copy) {
  from ...
  into ...
  filter { String line -> line.reverse() }
}

```

Inside the closure you can do whatever is needed to make the replacement happen. For example you can use Java regular expressions.
